Using middlewares
Built-in
import AsyncStorage from '@react-native-async-storage/async-storage'
import { createStore } from '@colorfy-software/zfy'
const data = { name: 'zfy' }
type StoreDataType = typeof data
const store = createStore<StoreDataType>('store', data, {
persist: { getStorage: () => AsyncStorage },
subscribe: true,
log: true,
})
const listener = (newName, oldName) => console.log({ newName, oldName })
const unsubscribe = store.subscribeWithSelector?.(
state => state.data.name,
listener,
{ fireImmediately: true }
)Custom
Last updated