Part of the zustand package: install zustand and import these from zustand/middleware.
Functions
combine
tsfunction combine<
T extends object,
U extends object,
Mps extends [StoreMutatorIdentifier, unknown][] = [],
Mcs extends [StoreMutatorIdentifier, unknown][] = [],
>(
initialState: T,
create: StateCreator<T, Mps, Mcs, U>,
): StateCreator<Write<T, U>, Mps, Mcs>
createJSONStorage
tsfunction createJSONStorage<S, R = unknown>(
getStorage: () => StateStorage<R>,
options?: JsonStorageOptions,
): PersistStorage<S, unknown> | undefined
unstable_ssrSafe
tsfunction ssrSafe<
T extends object,
U extends object,
Mps extends [StoreMutatorIdentifier, unknown][] = [],
Mcs extends [StoreMutatorIdentifier, unknown][] = [],
>(
config: StateCreator<T, Mps, Mcs, U>,
isSSR: boolean = typeof window === 'undefined',
): StateCreator<T, Mps, Mcs, U>
Constants
devtools
tsconst devtools: Devtools
persist
tsconst persist: Persist
redux
tsconst redux: Redux
subscribeWithSelector
tsconst subscribeWithSelector: SubscribeWithSelector
Interfaces
DevtoolsOptions
tsinterface DevtoolsOptions extends Config
Properties
| Name | Type | Default | Description |
|---|---|---|---|
name? | string | ||
enabled? | boolean | ||
anonymousActionType? | string | ||
store? | string |
PersistOptions
tsinterface PersistOptions<
S,
PersistedState = S,
PersistReturn = unknown,
>
Properties
| Name | Type | Default | Description |
|---|---|---|---|
name | string | Name of the storage (must be unique) | |
storage? | PersistStorage<PersistedState, PersistReturn> | undefined | createJSONStorage(() => window.localStorage) | Use a custom persist storage. |
partialize? | (state: S) => PersistedState | Filter the persisted value. | |
onRehydrateStorage? | ( state: S, ) => ((state?: S, error?: unknown) => void) | void | A function returning another (optional) function. The main function will be called before the state rehydration. The returned function will be called after the state rehydration or when an error occurred. | |
version? | number | If the stored state's version mismatch the one specified here, the storage will not be used. This is useful when adding a breaking change to your store. | |
migrate? | ( persistedState: unknown, version: number, ) => PersistedState | Promise<PersistedState> | A function to perform persisted state migration. This function will be called when persisted state versions mismatch with the one specified here. | |
merge? | (persistedState: unknown, currentState: S) => S | A function to perform custom hydration merges when combining the stored state with the current one. By default, this function does a shallow merge. | |
skipHydration? | boolean | false | An optional boolean that will prevent the persist middleware from triggering hydration on initialization, This allows you to call rehydrate() at a specific point in your apps rendering life-cycle. |
PersistStorage
tsinterface PersistStorage<S, R = unknown>
Properties
| Name | Type | Default | Description |
|---|---|---|---|
getItem | ( name: string, ) => StorageValue<S> | null | Promise<StorageValue<S> | null> | ||
setItem | (name: string, value: StorageValue<S>) => R | ||
removeItem | (name: string) => R |
StateStorage
tsinterface StateStorage<R = unknown>
Properties
| Name | Type | Default | Description |
|---|---|---|---|
getItem | (name: string) => string | null | Promise<string | null> | ||
setItem | (name: string, value: string) => R | ||
removeItem | (name: string) => R |
Types
NamedSet
tstype NamedSet<T> = WithDevtools<StoreApi<T>>['setState']
StorageValue
tstype StorageValue<S> = { … }
Properties
| Name | Type | Default | Description |
|---|---|---|---|
state | S | ||
version? | number |
Was this page helpful?