Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

Dispatch must be called inside of an event handler

ashcoding July 23, 2022

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>
  );
};

0 answers

Suggest an answer

Log in or Sign up to answer
DEPLOYMENT TYPE
CLOUD
PRODUCT PLAN
FREE
PERMISSIONS LEVEL
Product Admin
TAGS
AUG Leaders

Atlassian Community Events