Skip to content

Instantly share code, notes, and snippets.

@Jahans3 Jahans3/use-reducer.js
Last active Dec 1, 2018

Embed
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 }}>
{children}
</StateContext.Provider>
);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.