Skip to main content
Clarify title
Link
XML
  • 19.5k
  • 9
  • 67
  • 69

How to wait for redux Redux thunk: how to dispatchawait completion of an async action

Source Link
Tuomas Toivonen
  • 23.8k
  • 52
  • 148
  • 248

How to wait for redux thunk to dispatch action

As redux thunk calls functions returned by action creators asynchronously, how I can ensure after calling the action creator that redux has actually dispatched the action before moving on?

I need to fetch CSRF token before each POST request to server, and for both procedure there's an corresponding action.

The problem is, if I call those action creators successively, POST action is for some reason getting dispatched before CSRF action is dispatched. I want to keep these concerns separated, so I don't want to combine the actions.

How I can synchronize the action creator calling code with redux thunk dispatching those actions?