You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
import{createStore,combineReducers,applyMiddleware,compose}from'redux';import{rememberReducer,rememberEnhancer}from'redux-remember';constmyStateIsRemembered=(state='',action)=>{switch(action.type){case'SET_TEXT1':
returnaction.payload;default:
returnstate;}};constmyStateIsForgotten=(state='',action)=>{switch(action.type){case'SET_TEXT2':
returnaction.payload;default:
returnstate;}}constreducers={
myStateIsRemembered,
myStateIsForgotten
};constrememberedKeys=['myStateIsRemembered'];// 'myStateIsForgotten' will be forgotten, as it's not in this listconstreducer=rememberReducer(combineReducers(reducers));conststore=createStore(reducer,compose(applyMiddleware(// ...),rememberEnhancer(window.localStorage,// or window.sessionStorage, or your own custom storage driverrememberedKeys)));// Continue using the redux store as usual...
Legacy usage - react native
importAsyncStoragefrom'@react-native-community/async-storage';import{createStore,combineReducers,applyMiddleware,compose}from'redux';import{rememberReducer,rememberEnhancer}from'redux-remember';constmyStateIsRemembered=(state='',action)=>{switch(action.type){case'SET_TEXT1':
returnaction.payload;default:
returnstate;}};constmyStateIsForgotten=(state='',action)=>{switch(action.type){case'SET_TEXT2':
returnaction.payload;default:
returnstate;}};constreducers={
myStateIsRemembered,
myStateIsForgotten
};constrememberedKeys=['myStateIsRemembered'];// 'myStateIsForgotten' will be forgotten, as it's not in this listconstreducer=rememberReducer(combineReducers(reducers));conststore=createStore(reducer,compose(applyMiddleware(// ...),rememberEnhancer(AsyncStorage,// or your own custom storage driverrememberedKeys)));// Continue using the redux store as usual...
Legacy usage - inside a reducer
import{REMEMBER_REHYDRATED,REMEMBER_PERSISTED}from'redux-remember';constdefaultState={isRehydrated: false,isPersisted: false};constreduxRemember=(state=defaultState,action)=>{switch(action.type){caseREMEMBER_REHYDRATED:
// "action.payload" is the Rehydrated Root Statereturn{isRehydrated: true};caseREMEMBER_PERSISTED:
return{
...state,isPersisted: true};default:
returnstate;}}exportdefaultreduxRemember;