Created
July 30, 2019 02:58
-
-
Save jeffscottward/3669146e8cc491825a75510edae048f1 to your computer and use it in GitHub Desktop.
State Management in 10 lines w/ React Context & Hooks
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
// From https://bit.ly/2XH31rw | |
import React, { createContext, useContext, useReducer } from "react"; | |
export const StateContext = createContext(); | |
export const StateProvider = ({ reducer, initialState, children }) => ( | |
<StateContext.Provider value={useReducer(reducer, initialState)}> | |
{children} | |
</StateContext.Provider> | |
); | |
export const useStateValue = () => useContext(StateContext); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment