How to use the redux-persist/lib/storage.getItem function in redux-persist

To help you get started, we’ve selected a few redux-persist examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github cboard-org / cboard / src / store.js View on Github external
/* eslint-disable no-underscore-dangle */
  const composeEnhancers =
    process.env.NODE_ENV !== 'production' &&
    typeof window === 'object' &&
    window.__REDUX_DEVTOOLS_EXTENSION_COMPOSE__
      ? window.__REDUX_DEVTOOLS_EXTENSION_COMPOSE__
      : compose;

  store = createStore(
    createReducer(),
    initialState,
    composeEnhancers(...enhancers)
  );

  // Check to ensure latest build version
  storage
    .getItem('buildVersion')
    .then(localVersion => {
      if (localVersion !== buildVersion) {
        // Purge store
        persistStore(store).purge();

        // Save the new build version in the local cache
        storage.setItem('buildVersion', buildVersion);
      } else {
        persistStore(store);
      }
    })
    .catch(() => {
      persistStore(store);
      storage.setItem('buildVersion', buildVersion);
    });