UNPKG

@stainless-code/persist

Version:

Hydration-aware persistence for any reactive store — zero-dep persistSource core; codecs, backends, cross-tab transport, source + framework hydration adapters ship as opt-in recipes

33 lines (32 loc) • 1.38 kB
import { t as HydrationSignal } from "../hydration-DclSpq51.mjs"; //#region src/adapters/frameworks/react.d.ts interface UseHydratedResult { /** * Gates UI flash only, never the state read — `useSelector` reads the * pre-hydration (initial) state unchanged until hydration lands. */ hydrated: boolean; } /** * Mount a `HydrationSignal` into the React lifecycle via `useSyncExternalStore`. * Returns ONLY `hydrated` — state reads go through `useSelector`. Null signal → * `hydrated: true` (store stays the same with or without persistence). Server * snapshot is always `true` (no storage server-side, nothing to gate) — the * SSR policy every framework adapter must implement per the * `HydrationSignal` adapter contract; this hook is the reference. * * @example * ```ts * // store module — hydration signal as a persist sidekick * const persist = persistStore(store, { name: "app:prefs:v1" }); * export const prefsHydration = toHydrationSignal(persist); * * // component — gate the hydrate flash, read state via useSelector as usual * const { hydrated } = useHydrated(prefsHydration); * const prefs = useSelector(store, (s) => s.prefs); * if (!hydrated) return <Skeleton />; * ``` */ declare function useHydrated(signal: HydrationSignal | null | undefined): UseHydratedResult; //#endregion export { UseHydratedResult, useHydrated };