Redux side-effects as a function of state.
- Reducers and action creators as pure functions;
- It is not a middleware, so setup and testing are super easy;
- Follows the same pattern as React (decide what to do based on the state and not the actions);
- Effects are pure functions.
Add it as a dependency in your project:
npm install --save redux-heat
Here is a simple example to fetch user details once the id of the user changes is the Redux store:
// Define a selector to define what data to check for changesconst getUserId = stateuserId// Action creatorsconst setUserDetails = type: 'SET_USER_DETAILS' payload: userconst notifyUserFetchFailed = type: 'FETCH_USER_FAILED' payload: econst fetchUser =// Describe the effect based on state changesconst fetchUserHeat =fn: fetchUserargs:onValue: setUserDetailsonError: notifyUserFetchFailed// Then subscribe the effect to the Redux store