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.

const [state, setState] = useRGS<number>("counter", 1);
  • Type Parameters

    • T

    Parameters

    • key: string

      A unique key to identify the global store.

    • Optionalvalue: ValueType<T>

      The initial value of the global state. Can be a value or a function returning a value.

    • OptionalincludeRegExp: null | 0 | RegExp

      (Optional) A regular expression to specify which fields trigger updates.

    • OptionalexcludeRegExp: RegExp

      (Optional) A regular expression to specify which fields should be excluded from updates.

    Returns [T, SetStateAction<T>]

    A tuple containing the current state and a function to update the state.