The Atlassian Community Forums are currently in read-only mode. We will be relaunching on a new platform on September 22 (read more here). We apologize for the extended downtime. For concerns or questions, please email communitymanagers@atlassian.com. See you on the other side, on the new Atlassian Community Forums! :)

×

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

Comments for this post are closed

Community moderators have prevented the ability to post new answers.

DEPLOYMENT TYPE
CLOUD
PRODUCT PLAN
FREE
PERMISSIONS LEVEL
Product Admin
TAGS
AUG Leaders

Atlassian Community Events