SheetXL - v0.8.0-beta.9+sites.210.e2d420901
    Preparing search index...

    Function usePersistentState

    • Persisted state hook backed by the current persistence context.

      This works like useState, but:

      • The value is persisted under namespace:key using the current store.
      • With no stored value, it uses the provider's defaultValues[key] if present, otherwise defaultValue. Defaults are never written to the store; only values passed to setState are.
      • Then it hydrates asynchronously from the configured store (memory, localStorage, IndexedDB, remote, etc.). Hydration is seeding: a value written with setState while the read is still in flight is newer, so it wins and the read is discarded.
      • Writes are debounced according to debounceMs from the context.
      • Optional versioning + migration lets you evolve stored shapes over time.

      If key is null, persistence is disabled and the hook behaves like a plain useState with the same defaultValue semantics:

      • No reads or writes go to the persistence store.
      • No cross-tab / cross-hook subscription is set up.
      • clear() simply resets back to defaultValue (or undefined).

      Type Parameters

      • T = unknown

        Type of the stored value.

      Parameters

      • key: string | null

        Logical storage key; use null to disable persistence entirely.

      • OptionaldefaultValue: T | (() => T)

        Value used when nothing is stored and the provider has no default for key; a function is called lazily to produce it.

      • opts: PersistentStateOptions<T> = DefaultOptions

        Options controlling serialization, versioning, and migration.

      Returns [T, PersistentStateSetter<T>, () => void]

      A tuple of [state, setState, clear]:

      • state – The current value.
      • setState(next) – Updates the value and persists it (unless key === null).
      • clear() – Removes the persisted value and resets to the default.

      Like useState's setter, setState and clear keep a stable identity across renders, so they are safe in dependency lists.