Persist and rehydrate redux stores lazily.
The redux-persist
rehydration state for each reducer at it's initialisation.
If there are a lot of persistent reducers in a project, this can cause a performance problem, especially on low end devices.
The main idea of this library is to make state rehydration lazy, with backward compatibility with `redux-persist'.
persistReducer
and persistCombineReducers
returns Proxy
object as an initial state. When in the code we try to touch it via selectors, JSON.stringify
, actions, etc, the proxy synchronously rehydrates the state and returns it.
After rehydration, we only work with JS objects.
redux-persist-lazy
works only with synchronous storages like react-native-mmkv, localSotarge, etc.redux-persist-lazy
is not fully compatible withredux-persist
, although the migration should be smooth.
npm install redux-persist-lazy
Basic usage involves adding persistReducer and persistStore to your setup.
// configureStore.js
import { createStore } from 'redux'
import { persistStore, persistReducer } from 'redux-persist-lazy'
import { rootReducer } from './reducers'
import { mmkv } from './storage'
const persistConfig = {
key: 'slice',
storage: mmkv,
}
const persistedReducer = persistReducer(persistConfig, rootReducer)
const store = configureStore({
reducer: combineReducers({
slice: persistedReducer,
// ...
}),
})
See the contributing guide to learn how to contribute to the repository and the development workflow.
MIT
Made with create-react-native-library