react18-global-store
Version:
A simple yet elegant, light weight, react18 global store to replace Zustand for better tree shaking.
20 lines (19 loc) • 725 B
TypeScript
import type { SetStateAction, ValueType } from "./utils";
export type { SetterArgType, SetStateAction, Plugin } from "./utils";
/**
* 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<number>("counter", 1);
* ```
*
* @param key - Unique key to identify the store.
* @param value - Initial value of the store.
* @returns - A tuple (Ordered sequance of values) containing the state and a function to set the state.
*/
declare const useRGS: <T>(key: string, value?: ValueType<T>) => [T, SetStateAction<T>];
export { useRGS };