Implementing a Loading Indicator

Learn how to implement a spinner in your application.

Loading image

A common question when using Redux is how to show a spinner when server requests are in progress. The middleware approach provides an answer using additional dispatch() calls. Before a request starts or after it completes, we can dispatch a special action to be caught by reducers responsible for the UI state.

Here, we dispatch an apiStart() action before starting any server communication and dispatch apiFinish() on both successful and failed server responses:

Get hands-on with 1200+ tech skills courses.