import React, { createContext, useState, useEffect, useCallback } from "react" export const StateContext = createContext(null) export const StateProvider = (props: any): JSX.Element => { const [state, setState] = useState({}) const addState = useCallback( (newState: any) => { setState(prevState => { return { ...prevState, ...newState } }) }, [] ) useEffect(() => { try { window.addState = addState } catch { // nothing } }, []) return {props?.children} } export const withState = (Component: any) => (props: any) => ( {props => } ) export interface StateContextInterface { state: any addState: any }