Skip to content

Instantly share code, notes, and snippets.

View Nathan-Schwartz's full-sized avatar

Nathan Schwartz Nathan-Schwartz

View GitHub Profile
import React, {createContext, useReducer} from 'react';
import { Subtract } from 'utility-types';
import type { ReactNode } from 'react';
export default function buildStateManager<ContextState extends {}>(reducer: (ContextState, Object) => ContextState, initialState: ContextState) {
const context = createContext<{ state?: ContextState, dispatch?: Function }>(initialState);
const { Provider, Consumer } = context;
const StateProvider = ({ children }) => {