How to use the redux-persist.autoRehydrate 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 MacKentoch / react-redux-nextjs-bootstrap-starter / redux / store / configureStore.dev.js View on Github external
// #region configure logger middleware
const loggerMiddleware = createLogger({
  level:      'info',
  collapsed:  true
});
// #endregion

// #region createStore : enhancer
const enhancer = composeWithDevTools(
  applyMiddleware(
    thunkMiddleware,
    fetchMiddleware,
    loggerMiddleware,
  ),
  autoRehydrate()
);
// #endregion

// #region store initialization
export default function configureStore(initialState) {
  const store = createStore(reducer, initialState, enhancer);

  // begin periodically persisting the store
  persistStore(store);

  // OPTIONAL: you can blacklist reducers to avoid them to persist, so call
  // persistStore(
  //   store,
  //   {blacklist: ['someTransientReducer']},
  //   () => {
  //   console.log('rehydration complete')
github infinitered / ChainReactApp2017 / App / Redux / CreateStore.js View on Github external
/* ------------- Saga Middleware ------------- */

  const sagaMonitor = __DEV__ ? console.tron.createSagaMonitor() : null
  const sagaMiddleware = createSagaMiddleware({ sagaMonitor })
  middleware.push(sagaMiddleware)

  /* ------------- Assemble Middleware ------------- */

  enhancers.push(applyMiddleware(...middleware))

  /* ------------- AutoRehydrate Enhancer ------------- */

  // add the autoRehydrate enhancer
  if (ReduxPersist.active) {
    enhancers.push(autoRehydrate())
  }

  // if Reactotron is enabled (default for __DEV__), we'll create the store through Reactotron
  const createAppropriateStore = Config.useReactotron ? console.tron.createStore : createStore
  const store = createAppropriateStore(rootReducer, compose(...enhancers))

  // configure persistStore and check reducer version number
  if (ReduxPersist.active) {
    RehydrationServices.updateReducers(store)
  }

  // kick off root saga
  sagaMiddleware.run(rootSaga)

  return store
}
github squatsandsciencelabs / OpenBarbellApp / app / redux / Store.js View on Github external
const sagaMonitor = Reactotron.createSagaMonitor();
        var sagaMiddleware = createSagaMiddleware({sagaMonitor});
        const middlewares = applyMiddleware(
            thunk,
            sagaMiddleware
        );
        const enhancers = compose(middlewares, autoRehydrate());        
        var store = Reactotron.createStore(reducers, enhancers);
    } else {
        // release mode
        var sagaMiddleware = createSagaMiddleware();
        const middlewares = applyMiddleware(
            thunk,
            sagaMiddleware
        );
        const enhancers = compose(middlewares, autoRehydrate());        
        var store = createStore(reducers, enhancers);
    }

    // run sagas
    sagaMiddleware.run(Sagas);
    
    // load previous
    if (Platform.OS === 'ios') {
        var storageMechanism = AsyncStorage;
    } else {
        var storageMechanism = FilesystemStorage;
    }
    const fsPersistor = persistStore(store, {
        storage: storageMechanism,
        blacklist: [
            'scannedDevices',
github ello / webapp / src / store.js View on Github external
const serverInitState = window.__INITIAL_STATE__
  if (serverInitState) {
    Object.keys(serverInitState).forEach((key) => {
      serverInitState[key] = Immutable.fromJS(serverInitState[key])
    })
  }
  const initialState = serverInitState || passedInitialState
  // react-router-redux doesn't know how to serialize
  // query params from server-side rendering, so we just kill it
  // and let the browser reconstruct the router state
  initialState.routing = Immutable.Map()

  if (window.__GLAM__) { rehydrate(window.__GLAM__) }

  const store = compose(
    autoRehydrate({ stateReconciler }),
    applyMiddleware(
      sagaMiddleware,
      reduxRouterMiddleware,
      logger,
    ),
  )(createStore)(reducer, initialState)
  store.close = () => store.dispatch(END)

  store.sagaTask = sagaMiddleware.run(rootSaga)
  return store
}
github Twilio-org / phonebank / public / src / store.jsx View on Github external
admin_questions: adminQuestionsReducer,
  admin_scripts: adminScriptsReducer,
  admin_contact_lists: adminContactListsReducer,
  admin_users: adminUsersReducer,
  calls: volunteerCallsReducer
});

const rootReducer = (state, action) => {
  const { type } = action;
  const newState = (type === LOGOUT_USER) ? undefined : state;
  return appReducer(newState, action);
};

const middleware = [immutable(), createLogger(), promise(), thunk];

const store = createStore(rootReducer, compose(applyMiddleware(...middleware), autoRehydrate()));

persistStore(store);

// to reset the store:
// persistStore(store).purge();

export default store;
github maichong / labrador-demo / src / redux / createStore.js View on Github external
middleware.push(sagaMiddleware);

  // log中间件
  const SAGA_LOGGING_BLACKLIST = ['EFFECT_TRIGGERED', 'EFFECT_RESOLVED', 'EFFECT_REJECTED'];
  if (__DEV__) {
    const logger = createLogger({
      predicate: (getState, { type }) => SAGA_LOGGING_BLACKLIST.indexOf(type) === -1
    });
    middleware.push(logger);
  }

  // 合并中间件
  enhancers.push(applyMiddleware(...middleware));

  // persist rehydrate
  enhancers.push(autoRehydrate());

  const store = createStore(rootReducer, compose(...enhancers));

  // persist
  persistStore(store, reduxPersist, () => store.dispatch(StartupActions.startup()));

  // kick off root saga
  sagaMiddleware.run(rootSaga);

  return store;
}
github datafornews / metada / react / src / store / store.js View on Github external
// import the root reducer
import combinedReducer from '../reducers/index';
import defaultState from './defaultState';

export const history = createBrowserHistory();

window.browser = (function () {
    return window.msBrowser ||
        window.browser ||
        window.chrome;
})();

const middleware = routerMiddleware(history);

const enhancers = compose(autoRehydrate(), applyMiddleware(middleware),
    window.devToolsExtension ? window.devToolsExtension() : f => f
);

const store = createStore(combinedReducer, defaultState, enhancers);

// Multi-language support

let languageToUse = localStorage.getItem('activeLanguage');
if (!languageToUse) {
    languageToUse = navigator.language || navigator.userLanguage;
    languageToUse = languageToUse.indexOf('fr') > -1 ? 'fr' : 'en';
}
const languages = ['en', 'fr'];
store.dispatch(initialize(languages));//, { defaultLanguage: 'fr' }));
const json = require('../static/texts/global.locale.json');
store.dispatch(addTranslation(json));
github streamr-app / streamr-web / src / configureStore.js View on Github external
export default function configureStore (history) {
  const store = createStore(
    rootReducer,
    composeWithDevTools(
      applyMiddleware(
        thunk,
        apiMiddleware,
        routerMiddleware(history)
      ),
      autoRehydrate()
    )
  )

  persistStore(store, { whitelist: ['user', 'auth'] })

  if (module.hot) {
    module.hot.accept('./reducers', () => {
      const nextRootReducer = require('./reducers/index')
      store.replaceReducer(nextRootReducer)
    })
  }

  return store
}
github egovernments / egov-services / web / common-web / src / store.js View on Github external
import { createStore, compose, applyMiddleware } from 'redux';
import thunk from 'redux-thunk';
import { persistStore, autoRehydrate } from 'redux-persist';
import reducers from './reducer';

const store = createStore(
  reducers,
  {},
  compose(
    applyMiddleware(thunk),
    autoRehydrate()
  )
);

//persistStore(store);

export default store;
github StephenGrider / AdvancedReactNative / jobs / store / index.js View on Github external
import { createStore, compose, applyMiddleware } from 'redux';
import thunk from 'redux-thunk';
import { persistStore, autoRehydrate } from 'redux-persist';
import { AsyncStorage } from 'react-native';
import reducers from '../reducers';

const store = createStore(
  reducers,
  {},
  compose(
    applyMiddleware(thunk),
    autoRehydrate()
  )
);

persistStore(store, { storage: AsyncStorage, whitelist: ['likedJobs'] });

export default store;