Created
June 14, 2019 18:34
-
-
Save gaizka-allende/8d5001837415e41fde297592e8873c82 to your computer and use it in GitHub Desktop.
combineReducers for useReducer
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const combineReducers = reducers => ( | |
state, | |
action, | |
) => reducers.reduce( | |
( | |
newState, | |
reducer, | |
) => reducer( | |
newState, | |
action, | |
), | |
state, | |
); | |
export default combineReducers; | |
and I call it like this: | |
const [state, dispatch] = useReducer( | |
combineReducers( | |
[ | |
reduder1, | |
reducer2, | |
], | |
), | |
{ | |
...initialAuctionState, | |
...initialLinkedDealsState, | |
}, | |
); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment