Skip to Content
API Reference

API Reference

Generated from the type declarations published with the package.

createStorage

Parameters:
NameTypeDefault
sourceStorageSource

'local', 'session', a Storage, or a function returning one

schemaS

Each key and how its value is stored (see string, number…)

optionsCreateStorageOptions

clearOnDefault and prefix

Returns:
TypedStorage<S>

TypedStorage

NameTypeDefault
schemaSchema

The schema the store was created with

lengthnumber

Number of schema keys currently set

getItem<K extends string>(key: K) => any

Returns the value of a key, or its default when missing or invalid

setItem<K extends string>(key: K, value: any) => void

Stores a value. Setting the default removes the key (see clearOnDefault). Like localStorage.setItem, throws when the storage is full.

removeItem<K extends string>(key: K) => void

Removes a key, so it reads as its default

clear() => void

Removes every schema key. Other keys in the storage are left untouched

key(index: number) => string | null

Returns the name of the n-th schema key currently set, or null

addEventListener(type: "change", listener: StorageChangeListener<Schema>) => void

Listens to changes made in this tab and in other tabs

removeEventListener(type: "change", listener: StorageChangeListener<Schema>) => void

Removes a listener added with addEventListener

createCookieStore

Parameters:
NameTypeDefault
schemaS

Each cookie and how its value is stored (see string, number…)

optionsCreateCookieStoreOptions

Default cookie attributes, clearOnDefault and prefix

Returns:
TypedCookieStore<S>

CookieOptions

NameTypeDefault
pathstring

URL path the cookie is sent for (default: '/')

domainstring

Domain the cookie is sent to, e.g. 'example.com' to include subdomains

maxAgenumber

Lifetime in seconds

expiresnumber | Date

Expiry date, or a timestamp in milliseconds

sameSite"strict" | "lax" | "none"

Cross-site sending policy. 'none' requires secure: true in browsers

secureboolean

Only send the cookie over HTTPS

partitionedboolean

Partition the cookie per top-level site (CHIPS)

useItem

From parsistent/react.

Parameters:
NameTypeDefault
storeAnyStore<S>
keyK
Returns:
[value: inferValue<S[K]>, setValue: (action: SetItemAction<inferValue<S[K]>, inferInput<S[K]>>) => void]

CookieProvider

NameTypeDefault
cookiesCookieRecord

Request cookies, from cookieStore.fromHeader(...).cookies. Only pass that filtered record: it ends up in client-side props.

childrenReactNode

Value

NameTypeDefault
parse(raw: string) => unknown

Converts a stored string into a value, returning null (or throwing) when invalid

serialize(value: unknown) => string

Converts a value into the string to store

eq(valueA: unknown, valueB: unknown) => boolean

Compares two values (default: ===)

defaultValueunknown

Returned when the key is missing or its stored value is invalid

type"single"

Only single-value parsers are supported (nuqs multi parsers are rejected)

Last updated on