Skip to content

Instantly share code, notes, and snippets.



Last active Dec 1, 2018
What would you like to do?
Use reducer
export function StateProvider ({ state: initialState, reducers, middleware, children }) {
const [state, dispatch] = useReducer((state, action) => {
return reducers.reduce((state, reducer) => reducer(state, action) || state, state);
}, initialState);
return (
<StateContext.Provider value={{ state, dispatch }}>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment