type Listener = () => void; export type SetterArgType = T | ((prevState: T) => T); export type SetStateAction = (value: SetterArgType) => void; export type ValueType = T | (() => T); /** * This is a hack to reduce lib size + readability + not encouraging direct access to globalThis */ type RGS = { v: unknown; l: Listener[]; s: SetStateAction | null; }; declare global { var rgs: Record; } export declare const globalRGS: Record; /** setter function to set the state. */ export declare const createSetter: (key: string) => SetStateAction; /** Extract coomon create hook logic to utils */ export declare const createHook: (key: string) => [T, SetStateAction]; type Mutate = (value?: T) => void; export type Plugin = { init?: (key: string, value: T | undefined, mutate: Mutate) => void; onChange?: (key: string, value?: T) => void; }; /** Initialize the named store when invoked for the first time. */ export declare const initWithPlugins: (key: string, value?: ValueType, plugins?: Plugin[], doNotInit?: boolean) => void; /** * Use this hook similar to `useState` hook. * The difference is that you need to pass a * unique key - unique across the app to make * this state accessible to all client components. * * @example * ```tsx * const [state, setState] = useRGS("counter", 1); * ``` * * @param key - Unique key to identify the store. * @param value - Initial value of the store. * @param plugins - Plugins to be applied to the store. * @param doNotInit - Do not initialize the store. Useful when you want to initialize the store later. Note that the setter function is not available until the store is initialized. * @returns - A tuple (Ordered sequance of values) containing the state and a function to set the state. */ export declare const useRGSWithPlugins: (key: string, value?: ValueType, plugins?: Plugin[], doNotInit?: boolean) => [T, SetStateAction]; export {};