PersistOptions
Properties
Section titled “Properties”adapter
Section titled “adapter”adapter: PersistAdapter;debounceMs?
Section titled “debounceMs?”optional debounceMs?: number;Coalesce writes for this long. Default 100.
optional keys?: string[];Persist only these keys. Default: every key that has been written.
migrate?
Section titled “migrate?”optional migrate?: (state, from) => Record<string, unknown>;Bring persisted state written at an older version up to the current one.
Return the migrated state; the version clocks are carried over untouched,
so a migrated value keeps its place in the last-writer-wins order.
Only called when from is older. Newer data — an older build reading what
a newer one wrote — is refused instead, because a build cannot be asked to
understand a shape that postdates it. That is the same call the wire makes
for a protocol version it does not know.
Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
state | Record<string, unknown> |
from | number |
Returns
Section titled “Returns”Record<string, unknown>
onRestoreError?
Section titled “onRestoreError?”optional onRestoreError?: (error) => void;Called when persisted state is refused instead of restored. The store keeps its initial values and carries on either way — this is how you find out, and the default is a development warning.
Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
error | RestoreError |
Returns
Section titled “Returns”void
version?
Section titled “version?”optional version?: number;The version of your state’s shape. Bump it whenever a key changes meaning or type, and supply migrate to carry old data forward.
Disk is where version skew has its longest fuse. A wire from another deploy is gone in a second; a value written by last month’s build sits there until someone reopens the tab, and then restores with a clock that beats every live tab. Without a version there is no way to even notice.
Default 0, which is also what anything written before this existed reads as
— so adding version: 1 and a migrate is enough to adopt it.