最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - What is the use of autoRehydrate in redux-persist and why it was removed on v5? - Stack Overflow

programmeradmin0浏览0评论

I couldn't find anything on the GitHub page of ReduxPersist

I have a piece of code I'm trying to understand and as this autoRehydrate was removed, I would like to know how the code should be implemented with version 5 of redux-persist.

import { AsyncStorage } from 'react-native';
import { applyMiddleware, createStore } from 'redux';
import { autoRehydrate, persistStore } from 'redux-persist'
import thunk from 'redux-thunk';
import reducers from '../reducers';

const middleWare = [thunk];

const createStoreWithMiddleware = applyMiddleware(...middleWare)(createStore);

 export default configureStore = (onComplete) => {
  const store = autoRehydrate()(createStoreWithMiddleware)(reducers);
  persistStore(store, { storage: AsyncStorage }, onComplete);

  return store;
};

I've found some tutorials, but it just says this autoRehydrate must be there but doesn't explain what it actually does.

I couldn't find anything on the GitHub page of ReduxPersist

I have a piece of code I'm trying to understand and as this autoRehydrate was removed, I would like to know how the code should be implemented with version 5 of redux-persist.

import { AsyncStorage } from 'react-native';
import { applyMiddleware, createStore } from 'redux';
import { autoRehydrate, persistStore } from 'redux-persist'
import thunk from 'redux-thunk';
import reducers from '../reducers';

const middleWare = [thunk];

const createStoreWithMiddleware = applyMiddleware(...middleWare)(createStore);

 export default configureStore = (onComplete) => {
  const store = autoRehydrate()(createStoreWithMiddleware)(reducers);
  persistStore(store, { storage: AsyncStorage }, onComplete);

  return store;
};

I've found some tutorials, but it just says this autoRehydrate must be there but doesn't explain what it actually does.

Share Improve this question edited Sep 18, 2018 at 21:45 Pritish Vaidya 22.2k4 gold badges61 silver badges78 bronze badges asked Sep 18, 2018 at 20:35 noone000noone000 1572 silver badges10 bronze badges
Add a ment  | 

1 Answer 1

Reset to default 5

autoRehydrate means calling for the persist/REHYDRATE action to read the persisted state from the disk (which you have persisted before) which can be merged back to the original state.

In the migration guide from v4 to v5, they have introduced a PersistGate.

This delays the rendering of your app's UI until your persisted state has been retrieved and saved to redux.

Therefore all the rehydration actions will be handled by it under the hood.

发布评论

评论列表(0)

  1. 暂无评论