I am trying to load some data from the storage API with a 'Load' component but only once. How do I set 'loaded' to true in the following code after Load() has been called? If I try to call setLoaded(true) in the Load component, I get the exception shown below.
const App = () => {
const [loaded, setLoaded] = useState(false);
var errMsg;
function Load() {
[errMsg] = useState(storage.get("ErrMsg"));
//setLoaded(true); //Throws the following exception //dispatch must be called inside of an event handler or within the function arguments of
//useAction, useState or useContentProperty
}
return (
<Fragment>
<Form>
<TextField name="errormessage" label="Error Message" defaultValue={errMsg} />
</Form>
{!loaded && (
<Load />
)}
</Fragment>
);
};