Accepted answer

You can use useEffect hook that depends on your state show.

useEffect(() => { props.dispatch(actions.loadAll());},[show]);

Using this chunk of code when the show state changes, the useEffect runs. So when your modal opens, your data is loaded.


Like s.hesam said

use condition to load the data only if the modal open.

I add the condition if the modal open the first time - fisrtTimeLoad

fisrtTimeLoad - can be the data in the state that exist and you put it as another condition.

useEffect(() => {
    if (show && fisrtTimeLoad) props.dispatch(actions.loadAll());
  }, [show, fisrtTimeLoad]);

Related Query

More Query from same tag