In my react-redux application, I have an action creator which makes 4 server calls, first three calls are made async and then last one waits on the response of 3rd call.
Lets us say someone changes the route before response of 3rd came, 4th call wont be made. How can I ensure this does not happen?
Either I should not allow route change until actioncreator has done its job (users won't like this). Or, I should allow 4th call to happen even if the route is changed, looks like a reasonable solution from users perspective. I don't know how to code any of the solution, please opine.
Note: Route change can happen from navigation bar on the top.
You can choose one of this:
Also you could use server-side rendering to prefetch data from API.
Method 1 -
If you want to show a non dismissible overlay to the user while your API call is running, you can do so like this -
You can create a separate Modal component like above and import it where you want to use it. Visibility can be toggle by any state variable which is accessible in your api call.
Method 2 - Ideally, even if your route changes, it should not effect your action and action creators and your async api calls should run as it is. You may have not implemented the api calls properly. You can use redux saga like this -
Pseudo Code: