Created
September 29, 2020 20:41
-
-
Save reireynoso/dbddddf1c8fd5688ae250feda83d534f to your computer and use it in GitHub Desktop.
Context API file
This file contains hidden or 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
import React, { createContext, useContext, useReducer } from "react"; | |
export const StateContext = createContext(); | |
export const Provider = ({ reducer, initialState, children }) => ( | |
<StateContext.Provider value={useReducer(reducer, initialState)}> | |
{children} | |
</StateContext.Provider> | |
); | |
export const globalStateValue = () => useContext(StateContext); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment