UNPKG

@react-libraries/use-global-state

Version:
52 lines (51 loc) 2.45 kB
import { Dispatch, SetStateAction } from 'react'; declare type CacheType = { [key: string]: unknown; }; declare type UpdateType = (newValue: CacheType, oldValue: CacheType) => void; declare type Render<T = unknown> = Dispatch<SetStateAction<T | undefined>>; export declare type ContextType = { renderMap: Map<string, Set<Render>>; initialKeys: Set<string>; initialDatas: Map<string, unknown>; updateEvents: Set<UpdateType>; cache: CacheType; }; export declare const addUpdateEvent: (onUpdate: UpdateType) => void; export declare const removeUpdateEvent: (onUpdate: UpdateType) => void; export declare const Provider: ({ value, onUpdate, children, }: { value?: CacheType | undefined; onUpdate?: UpdateType | undefined; children?: React.ReactNode; }) => import("react").FunctionComponentElement<{ value: ContextType; }>; export declare const reset: (context?: ContextType) => void; export declare const clearCache: (keys: string | string[], context?: ContextType) => void; export declare const getCache: <T = unknown>(keys: string | string[], cache?: CacheType) => { [key: string]: T; }; export declare const setCache: <T = unknown>(src: CacheType, context?: ContextType) => void; export declare const createContextCache: (values: ReadonlyArray<readonly [string | string[], unknown]>) => { [k: string]: unknown; }; export declare const query: <T = unknown>(keys: string | string[], context?: ContextType) => T; export declare const mutate: <T = Object>(keys: string | string[], data: T | Promise<T> | ((data: T) => T | Promise<T>), context?: ContextType) => void; export declare const mutates: <T = Object>(values: { [key: string]: T; }, context?: ContextType) => void; export declare const useQuery: () => <T = unknown>(keys: string | string[]) => T; export declare const useMutation: () => <T>(keys: string | string[], state: T | Promise<T> | ((data: T) => T | Promise<T>)) => void; export declare const useGlobalState: { <T>(keys: string | string[], initialData: T | (() => T)): readonly [ T, (data: T | ((data: T) => T)) => void ]; <K = unknown, T = K | undefined>(keys: string | string[]): readonly [ T, (data: T | ((data: T) => T)) => void ]; }; export declare const storageName = "@react-libraries/use-global-state"; export declare const setLocalStorage: (flag?: boolean) => void; export {};