UNPKG

react19-store

Version:

A simple yet elegant, light weight, react18 global store to replace Zustand for better tree shaking.

29 lines (28 loc) 1.19 kB
import { useRGSWithPlugins } from "./utils"; import type { Plugin, SetStateAction } from "./utils"; /** * Creates a store with plugins. * @example * * ```tsx * // in hook file, e.g., store.ts * export const useMyRGS = create<type>(key, value, plugins); * * // in component file * const [state, setState] = useMyRGS(); * ``` * * @param key - Unique key to identify the store. * @param value - Initial value of the store. * @param plugins - Plugins to be applied to the store. * @returns - A hook function that returns a tuple (Ordered sequence of values) containing the state and a function to set the state. */ export declare const create: <T>(key: string, value?: T, plugins?: Plugin<T>[]) => (() => [T, SetStateAction<T>]); /** * Creates a hook similar to useRGS, but with plugins to be applied on first invocation. * * @param plugins - Plugins to be applied to the store. * @returns A hook that automatically initializes the store (if not already initialized) with the given plugins. */ export declare const withPlugins: <T>(plugins: Plugin<T>[]) => (<U = T>(key: string, value?: U, doNotInit?: boolean) => [U, SetStateAction<U>]); export { useRGSWithPlugins };