I've got this functional component:
export const Special = (props) => {
const [data, setData] = useState();
const [loading, setLoading] = useState(true);
const dataRead = (dt) => {
setData(dt);
setLoading(false);
}
useEffect(() => {
setLoading(true);
fetch("/reportTypes/search/visible")
.then( (response) => response.json() )
.then( dataRead)
.catch( (err) => {
setLoading(false);
});
}, []);
if ( loading ) return (<Loading />);
return (
<div className="Special">
<Labeled label="Pricing">
{JSON.stringify(data)}
</Labeled>
</div>
);
}
If I remove one of setData(dt) or setLoading(false) from dataRead method it works. However if both are present, I get an error:
Uncaught Error: Element type is invalid: expected a string (for built-in components) or a class/function (for composite components) but got: undefined. You likely forgot to export your component from the file it's defined in, or you might have mixed up default and named imports.
I tried calling this without useEffect - same result. I tried useEffect with square brackets as above, and without. I tried various configurations. No matter how, but calling both setData and setLoading causes this error. Removing one of them makes it OK. I'm fresh to react so there must be something I missing.