Back to home

Redux Persist With React Native main image

Redux Persist With React Native

1 yarn add redux-persist redux-persist-sensitive-storage
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 import { persistStore, persistReducer } from "redux-persist"; import storage from "redux-persist/lib/storage"; import { PersistGate } from "redux-persist/es/integration/react"; // if you need to persist import createSensitiveStorage from "redux-persist-sensitive-storage"; Amplify.configure(config); const sagaMiddleware = createSagaMiddleware(); const enhancers = []; const reducers = combineReducers({ copy: CopyReducer, auth: AuthReducer, navigation: NavReducer, }); enhancers.push(applyMiddleware(logger, reduxNavMiddleware, sagaMiddleware)); // persist updates const persistConfig = { key: "primary", storage, whitelist: __DEV__ ? ["CopyReducer", "OffersReducer", "StoresReducer"] : [ "CopyReducer", "ProfileReducer", "OffersReducer", "StoresReducer", "LoyaltyCardReducer", ], }; const configuredReducers = persistReducer(persistConfig, reducers); const store = createStore(configuredReducers, composeEnhancers(...enhancers)); /* if you need sensitive storage */ const persistor = persistStore(store, createSensitiveStorage(), () => console.info("Persist configured") ); /* else */ // const persistor = persistStore(store); export default class App extends Component { render() { return ( <Provider store={store}> <PersistGate persistor={persistor}> <ReduxNavigation /> </PersistGate> </Provider> ); } }

Dennis O'Keeffe

@dennisokeeffe92
  • Melbourne, Australia

Hi, I am a professional Software Engineer. Formerly of Culture Amp, UsabilityHub, Present Company and NightGuru.
I am currently working on workingoutloud.dev, Den Dribbles and LandPad .

Related articles


1,200+ PEOPLE ALREADY JOINED ❤️️

Get fresh posts + news direct to your inbox.

No spam. We only send you relevant content.