What is Redux middleware?
Without middleware, Redux enables us to dispatch actions as objects to then be sorted by the reducer. Some situations, such as server communication, require a bit more control over what gets sent and when.
Middleware sits in between the dispatched action and the reducer, enabling us to determine if any action needs to be taken before continuing. In the case of Redux Thunk, the middleware knows that if it receives a function it should run it rather than carry on. It can then dispatch its own actions as needed.
Once it’s finished with the action, it can pass it along to the reducer by calling ‘next’. This makes it possible to combine different middleware together without worrying about losing actions.
Middleware is readily available to be downloaded and used as part of a third-party package, but it can also be useful to keep other logic, such as analytics and error handling, away from the main application.