How to use the redux-persist.getStoredState 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 reduxjs / redux-devtools / packages / redux-devtools-core / src / app / store / configureStore.js View on Github external
export default function configureStore(callback, key) {
  const persistConfig = {
    keyPrefix: `redux-devtools${key || ''}:`,
    blacklist: ['instances', 'socket'],
    storage: localForage,
    serialize: data => data,
    deserialize: data => data
  };

  getStoredState(persistConfig, (err, restoredState) => {
    let composeEnhancers = compose;
    if (process.env.NODE_ENV !== 'production') {
      if (window.__REDUX_DEVTOOLS_EXTENSION_COMPOSE__) {
        composeEnhancers = window.__REDUX_DEVTOOLS_EXTENSION_COMPOSE__;
      }
      if (module.hot) {
        // Enable Webpack hot module replacement for reducers
        module.hot.accept('../reducers', () => {
          const nextReducer = require('../reducers'); // eslint-disable-line global-require
          store.replaceReducer(nextReducer);
        });
      }
    }

    const store = createStore(
      rootReducer,
github alphasp / pxview / src / common / store / getStoredStateMigrateToFileSystemStorage.js View on Github external
return async currentConfig => {
    const filePersistStorePath = `${RNFetchBlob.fs.dirs.DocumentDir}/persistStore`;
    const isFilePersistStoreExists = await RNFetchBlob.fs.exists(
      filePersistStorePath,
    );
    if (isFilePersistStoreExists) {
      const state = await getStoredState(currentConfig);
      return state;
    }
    return getStoredState(v5Config).then(v5State => {
      if (v5State) {
        return v5State;
      }
      return getStoredStateV4(v4Config);
    });
  };
}
github codejamninja / reactant / packages / redux / src / redux.web.server.js View on Github external
async getInitialState({ req, res }) {
    const { app, initialState } = this;
    const redux = {
      initialState
    };
    await callLifecycle('reduxApplyInitialState', app, { req, res, redux });
    if (req.redux.persist) {
      try {
        const state = await getStoredState(req.redux.persist);
        if (state) _.merge(redux.initialState, state);
      } catch (err) {}
    }
    return redux.initialState;
  }
github codejamninja / reactant / packages / base / src / createStore.js View on Github external
async function getInitialState({ cookieJar }, persistConfig) {
  const { initialState } = config;
  if (cookieJar) {
    try {
      const state = await getStoredState(persistConfig);
      if (state) return state;
    } catch (err) {
      return initialState;
    }
  }
  return initialState;
}
github zalmoxisus / crossbuilder / src / app / store / getStoredState.js View on Github external
export default function (configure, callback) {
  const persistConfig = typeof chrome !== 'undefined' && chrome.storage && chrome.storage.local ? {
    storage,
    skipRestore: true,
    serialize: data => data,
    deserialize: data => data,
    debounce: 0
  } : {
    skipRestore: true
  };
  getStoredState(persistConfig, (err, initialState) => {
    const store = configure(initialState);
    persistStore(store, persistConfig, () => { callback(store); });
  });
}
github codejamninja / reactant / src / store / create.js View on Github external
async function getInitialState(context, persistConfig) {
  if (context.cookieJar) {
    let preloadedState = initialState;
    try {
      preloadedState = await getStoredState(persistConfig);
    } catch (err) {}
    return preloadedState;
  }
  return initialState;
}
github codejamninja / reactant / packages / redux / src / redux.web.client.js View on Github external
async getInitialState() {
    const { app, initialState } = this;
    const redux = {
      initialState
    };
    await callLifecycle('reduxApplyInitialState', app, { redux });
    if (app.redux.persist) {
      try {
        const state = await getStoredState(app.redux.persist);
        if (state) return state;
      } catch (err) {
        return redux.initialState;
      }
    }
    return redux.initialState;
  }
github azlyth / hooks / js / store.js View on Github external
export async function verifyStorePassword(password) {
  let state = await getStoredState(createConfiguration(password));
  let incorrect = Object.values(state).includes(null);
  return !incorrect;
};
github alphasp / pxview / src / common / store / getStoredStateMigrateToFileSystemStorage.js View on Github external
return async currentConfig => {
    const filePersistStorePath = `${RNFetchBlob.fs.dirs.DocumentDir}/persistStore`;
    const isFilePersistStoreExists = await RNFetchBlob.fs.exists(
      filePersistStorePath,
    );
    if (isFilePersistStoreExists) {
      const state = await getStoredState(currentConfig);
      return state;
    }
    return getStoredState(v5Config).then(v5State => {
      if (v5State) {
        return v5State;
      }
      return getStoredStateV4(v4Config);
    });
  };
}