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