Skip to content

Instantly share code, notes, and snippets.

@reireynoso
Created September 29, 2020 20:41
Show Gist options
  • Save reireynoso/dbddddf1c8fd5688ae250feda83d534f to your computer and use it in GitHub Desktop.
Save reireynoso/dbddddf1c8fd5688ae250feda83d534f to your computer and use it in GitHub Desktop.
Context API file
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