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

I couldn't find anything on the GitHub page of ReduxPersistI have a piece of code I'm trying

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.

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745080164a4610076.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信