- Notifications
You must be signed in to change notification settings - Fork51
Reduce multiple reducers into a single reducer from left to right
License
NotificationsYou must be signed in to change notification settings
redux-utilities/reduce-reducers
Folders and files
| Name | Name | Last commit message | Last commit date | |
|---|---|---|---|---|
Repository files navigation
Reduce multiple reducers into a single reducer from left to right
npm install reduce-reducersimportreduceReducersfrom'reduce-reducers';constinitialState={A:0,B:0};constaddReducer=(state,payload)=>({ ...state,A:state.A+payload});constmultReducer=(state,payload)=>({ ...state,B:state.B*payload});constreducer=reduceReducers(initialState,addReducer,multReducer);conststate={A:1,B:2};constpayload=3;reducer(state,payload);// { A: 4, B: 6 }
Originally created to combine multiple Redux reducers that correspond to different actions (e.g.like this). Technically works with any reducer, not just with Redux, though I don't know of any other use cases.
This StackOverflow post explains it very well:https://stackoverflow.com/a/44371190/5741172
About
Reduce multiple reducers into a single reducer from left to right
Resources
License
Uh oh!
There was an error while loading.Please reload this page.
Stars
Watchers
Forks
Packages0
No packages published
Uh oh!
There was an error while loading.Please reload this page.
Contributors9
Uh oh!
There was an error while loading.Please reload this page.