InitStoresType

Interface representing the data structure of the initStores()method's output.

src/types.ts
import type { EqualityChecker } from 'zustand'

type InitStoresType<StoresDataType> = {
  stores: {
    [StoreNameType in keyof StoresDataType]: CreateStoreType<
      StoresDataType[StoreNameType]
    >
  } & {
    rehydrate: () => Promise<boolean>
    reset: (options?: InitStoresResetOptionsType<StoresDataType>) => void
  }
  useStores: <StoreNameType extends keyof StoresDataType, Output>(
    storeName: StoreNameType,
    selector: (data: StoresDataType[StoreNameType]) => Output,
    equalityFn?: EqualityChecker<Output>
  ) => Output
}
Unexpected error with integration github-files: Integration is not authenticated with GitHub

API reference

stores

stores.{storeName}

You can directly access all the zustand stores you provided to initStores() via the stores key. Example:

stores.rehydrate

Promise that allows you to manually rehydrate all the stores provided to initStores() that have the persist middleware enabled. Example:

stores.reset

Function that allows you to reset all (or part) of the stores you provided to initStores(). Example:

useStores

React Hook that allows you to consume the data from any of the store you provided to initStores().

You'd use it exactly like you'd use a regular zustand store Hook, with the only difference that useStores() expects the name of the store you want to get data from as its initial argument. Example:

Last updated

Was this helpful?