CreateStoreOptionsType

Interface of the 3rd (options)argument accepted by the createStore() method.

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

interface CreateStoreOptionsType<StoreDataType> {
  log?: boolean
  subscribe?: boolean
  persist?: Omit<
    PersistOptions<StoreType<StoreDataType>>,
    'name' | 'blacklist' | 'whitelist'
  > & {
    name?: string
    getStorage: Exclude<
      PersistOptions<StoreType<StoreDataType>>['getStorage'],
      undefined
    >
  }
  customMiddlewares?: ZfyMiddlewareType<StoreDataType>[]
}

API reference

log

log?: boolean

Setting this flag will enable/disable the custom logger middleware. The logger highlights the previous state, the payload of the update and the content of the new state.

There is a known bug if you're using Flipper as it doesn't allow syntax highlighting for logs (yet).

subscribe

subscribe?: boolean

Setting this flag will enable/disable the new subscribeWithSelector() middleware and make it accessible via createStore().subscribeWithSelector().

persist

  persist?: Omit<
    PersistOptions<StoreType<StoreDataType>>,
    'name' | 'blacklist' | 'whitelist'
  > & {
    name?: string
    getStorage: Exclude<
      PersistOptions<StoreType<StoreDataType>>['getStorage'],
      undefined
    >
  }

It uses the same PersistOptions as zustand's persist middleware with only 2 differences:

  • getStorage is now required instead of optional. This is due to the fact that zustand uses LocalStorage by default when this field is not provided, which wouldn't work with React Native.

  • name is now optional instead of required. This is because zfy simply uses the name you provided as createStore() 1st argument by default. Of course, you can still override it here if need be.

The detailed API reference is available here:

customMiddlewares

customMiddlewares?: ZfyMiddlewareType<StoreDataType>[]

This field allows you to provide middlewares to zfy. This could be one that you created yourself from scratch or a prebuilt zustand middleware that zfy doesn't already expose. Please refer to the Using middlewares guide if you want to know how to use this option.

Last updated