InitStoresType
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
storesstores.{storeName}
stores.{storeName}You can directly access all the zustand stores you provided to initStores() via the stores key. Example:
stores.rehydrate
stores.rehydratePromise that allows you to manually rehydrate all the stores provided to initStores() that have the persist middleware enabled. Example:
You shouldn't need to use this function as zustand stores rehydrate automatically:
if you want to perform some actions upon rehydration, look into the
onRehydrateStoragePersistOptions.if you want to hide/show your app depending on the rehydration status, see the
<PersistGate />component or the useRehydrate() Hook.
stores.reset
stores.resetFunction that allows you to reset all (or part) of the stores you provided to initStores(). Example:
useStores
useStoresReact 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:
useStores()really shines when you have a lot of stores in your app and don't want to have to import a lot of them/have a hard time remembering from which store you can get which data. You can now simply gather stores by topic/storage technology used/etc via initStores().
Last updated
Was this helpful?