Skip to content

Latest commit

 

History

History
23 lines (19 loc) · 591 Bytes

WRAPPER_ZUSTAND_PERSIST_MIDDLEWARE.md

File metadata and controls

23 lines (19 loc) · 591 Bytes

zustand persist-middleware wrapper

If you want to use MMKV with zustand persist-middleware, create the following storage object:

import { StateStorage } from 'zustand/middleware'
import { MMKV } from 'react-native-mmkv'

const storage = new MMKV()

const zustandStorage: StateStorage = {
  setItem: (name, value) => {
    return storage.set(name, value)
  },
  getItem: (name) => {
    const value = storage.getString(name)
    return value ?? null
  },
  removeItem: (name) => {
    return storage.delete(name)
  },
}