Skip to content

Instantly share code, notes, and snippets.

@jake-daniels
Last active February 19, 2019 08:58
Show Gist options
  • Save jake-daniels/917d61b73147b6e40a92884a2138bb90 to your computer and use it in GitHub Desktop.
Save jake-daniels/917d61b73147b6e40a92884a2138bb90 to your computer and use it in GitHub Desktop.
function initRedux(reducer, initialState) {
const StateContext = React.createContext(null)
const DispatchContext = React.createContext(null)
function Provider(props) {
const [appState, dispatch] = React.useReducer(reducer, initialState)
return (
<StateContext.Provider value={appState}>
<DispatchContext.Provider value={dispatch}>
{props.children}
</DispatchContext.Provider>
</StateContext.Provider>
)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment