r18gs
Version:
A simple yet elegant, light weight, react18 global store to replace Zustand for better tree shaking.
22 lines (21 loc) • 1.12 kB
TypeScript
import type { SetStateAction, ValueType } from "./utils";
export type { SetterArgType, SetStateAction, Plugin } from "./utils";
/**
* A React hook for managing shared global state, similar to the `useState` hook.
* This hook requires a unique key, which identifies the global store and allows state sharing across all client components.
*
* @example
* ```tsx
* const [state, setState] = useRGS<number>("counter", 1);
* ```
*
* @param key - A unique key to identify the global store.
* @param value - The initial value of the global state. Can be a value or a function returning a value.
* @param includeRegExp - (Optional) A regular expression to specify which fields trigger updates.
* @param excludeRegExp - (Optional) A regular expression to specify which fields should be excluded from updates.
* @returns A tuple containing the current state and a function to update the state.
*
* @see [Learn More](https://r18gs.vercel.app/)
*/
declare const useRGS: <T>(key: string, value?: ValueType<T>, includeRegExp?: RegExp | null | 0, excludeRegExp?: RegExp) => [T, SetStateAction<T>];
export { useRGS };