Skip to content
Persist
Esc
navigateopen⌘Jpreview
On this page

Getting started

Install Persist and wire hydration-aware persistence into any reactive store.

You already have a store. You need durable state without a first-paint flash — and without rewriting when the storage backend or store library changes.

Install

npm install @stainless-code/persist
pnpm add @stainless-code/persist
yarn add @stainless-code/persist
bun add @stainless-code/persist

Core is zero-dep. Each subpath is an optional peer — install only what you import. Full table: Entry points.

Peers for the quick-start imports below:

npm install seroval idb-keyval @tanstack/store react
pnpm add seroval idb-keyval @tanstack/store react
yarn add seroval idb-keyval @tanstack/store react
bun add seroval idb-keyval @tanstack/store react

Quick start

import { Store } from "@tanstack/store";
import { createSerovalStorage } from "@stainless-code/persist/codecs/seroval";
import { persistStore } from "@stainless-code/persist/sources/tanstack-store";
import { toHydrationSignal } from "@stainless-code/persist";
import { useHydrated } from "@stainless-code/persist/frameworks/react";

const store = new Store({ theme: "light" });
const persist = persistStore(store, {
  name: "app:prefs:v1",
  storage: createSerovalStorage(() => localStorage),
});
export const prefsHydration = toHydrationSignal(persist);

// in a component:
const { hydrated } = useHydrated(prefsHydration);

Compatibility

Runtime Supported range
Node ^20.19.0 || >=22.12.0
Bun >=1.0.0

Next

Last updated on July 20, 2026

Was this page helpful?