UNPKG

react-hooks-simple-global-state

Version:

Simple global state for React with Hooks, which just depends on React's useEffect and useState.

12 lines (11 loc) 560 B
declare type ValueOrFunc<T> = T | ((currentValue: T) => T); declare type FuncSetValue<T> = (newValueOrFunc: ValueOrFunc<T>) => void; export declare const useGlobalState: <T>(stateName: string, initValue?: T | undefined, listening?: boolean) => [currentValue: T, setValue: FuncSetValue<T>]; export default useGlobalState; interface AsyncData<T> { loading: boolean; data?: T; error?: any; refetch: () => void; } export declare const useAsyncGlobalState: <T>(stateName: string, funcLoadAsyncData?: (() => Promise<T>) | undefined) => AsyncData<T>;