Replies: 1 comment 2 replies
-
Dispatching a plain action is always synchronous, and the state update is complete as soon as the If you need to access the latest state right after a dispatch is complete, the right answer is to move this code into a thunk and do all the work there: function myThunk(someArg) {
return (dispatch, getState) => {
dispatch(someOtherAction(arg));
const updatedState = getState()
// do something with the updated state here
}
}
// in the component
const handleClick = () => {
dispatch(myThunk(123))
} |
Beta Was this translation helpful? Give feedback.
2 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Is there a way to await the completion of
dispatch
so that the following statement can be fired synchronously after their completion? Currently, I observe that the app selector in the function following the dispatch statements is not updated when invoking the API call.It would be fine to move the dispatch statements into the invoking call but is there a way to do something like
thread.join()
or some sort of await for the data.Code Example
Beta Was this translation helpful? Give feedback.
All reactions