Skip to content

Instantly share code, notes, and snippets.

@mzahor
Created March 14, 2019 22:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mzahor/934434f04cac6827f90f04af85db2163 to your computer and use it in GitHub Desktop.
Save mzahor/934434f04cac6827f90f04af85db2163 to your computer and use it in GitHub Desktop.
Super-simple react state management
import React, { createContext, useReducer, useContext } from "react";
export const StateContext = createContext();
export const useStateContext = () => useContext(StateContext);
export const StateProvider = ({ reducer, initialState, children }) => (
<StateContext.Provider value={useReducer(reducer, initialState)}>
{children}
</StateContext.Provider>
);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment