import * as React from 'react' ; import { createContext , useContext , useState } from 'react' ; import { ProviderProps } from './types' ; param initialValue function createGlobalState < T > ( initialValue ) { const ValueContext = React . createContext ( initialValue ) ; const UpdaterContext = createContext < React . Dispatch < React . SetStateAction < T > > > ( ( ) => null ) ; return const useStateValue = ( ) => useContext ( ValueContext ) ; return const useStateUpdate = ( ) => useContext ( UpdaterContext ) ; /**
     *
     * Provider Component which makes the state available to all the nested components
     */ const Provider = ( { children } ) => { const [ state , setState ] = useState ( initialValue ) ; return ( < ValueContext . Provider value = { state } > < UpdaterContext . Provider value = { setState } > { children } < /UpdaterContext.Provider> < /ValueContext.Provider>); } ; return { Provider , useStateValue , useStateUpdate } ; } export default createGlobalState ;