import React from 'react'; import { createGlobalState } from 'react-hooks-global-state'; type UseGlobalState = () => [ value: T, setValue: React.Dispatch> ]; // Create a hook that stores global state (shared across all hook instances). export const createGlobalStateHook = ( key: string, initialValue: T ): UseGlobalState => { const container = createGlobalState<{ [key: string]: T }>({ [key]: initialValue, }); const setGlobalState = (value: React.SetStateAction) => { container.setGlobalState(key, value); }; return () => [container.useGlobalState(key)[0], setGlobalState]; };