react-native-use-persist-storage
react-native-use-persist-storage copied to clipboard
useReducer like functionality
This is awesome. Is there any way or plans to also add persistent useReducer like functionality?
In case anyone else is looking for this, I did something like this myself, not quite as performant, but gets the job done, with this helper function:
// useStorage.ts
import { createPersistContext } from 'react-native-use-persist-storage'
export const useStorage = () => {
const [state, setState, loaded] = usePersistStorage('storageKey', initialState)
const update = (diff: Record<string, any>) => {
setState((prev) => ({ ...prev, ...diff }))
}
return { state, update, loaded }
}