Last Updated on May 6, 2022 by Pupli
- Redux middleware were designed to enable writing logic that has side effects
- “Side effects” are code that changes state/behavior outside a function, like AJAX calls, modifying function arguments, or generating random values
- Middleware add an extra step to the standard Redux data flow
- Middleware can intercept other values passed to
dispatch
- Middleware have access to
dispatch
andgetState
, so they can dispatch more actions as part of async logic
- Middleware can intercept other values passed to
- The Redux “Thunk” middleware lets us pass functions to
dispatch
- “Thunk” functions let us write async logic ahead of time, without knowing what Redux store is being used
- A Redux thunk function receives
dispatch
andgetState
as arguments, and can dispatch actions like “this data was received from an API response”
References
https://redux.js.org/tutorials/fundamentals/part-6-async-logic