Skip to content

Remote APIs

Billy Bunn edited this page May 2, 2019 · 1 revision

In Redux, normally all actions are used (dispatched) in-order or synchronously. This can become a real issue for applications that talk to external APIs/resources or perform side effects in our application.

To help handle this problem, Redux has middleware that can do things after an action is dispatched, but before that action (object) reaches the reducers. There are entire middleware libraries that help build these things into Redux, and one of the most popular is called Thunk.

Redux Thunk is a middleware that lets you call action creators that return a function instead of an action object. That function receives the store’s dispatch method, which is then used to dispatch regular synchronous actions inside the body of the function once the asynchronous operations have completed.

This makes it as simple as requiring "redux-thunk" into an application and wiring it into the Redux store: import thunk from 'redux-thunk';

Clone this wiki locally