我刚刚来到Redux。我试图通过redux-persist
将数据保存在本地存储上。我按照教程和存储在存储器中的数据进行了如下操作。
import {createStore, applyMiddleware, compose} from 'redux';
import {AsyncStorage} from 'react-native';
import {persistStore, autoRehydrate} from 'redux-persist';
import reducer from '../reducer';
var defaultState = {
todos: []
};
exports.configureStore = (initialState=defaultState) => {
var store = createStore(reducer, initialState, compose(
autoRehydrate()
));
persistStore(store, {storage: AsyncStorage});
return store;
}
这是我的App.js
。
import React, { Component } from 'react';
import {Provider} from 'react-redux';
import {
Platform,
StyleSheet,
Text,
View
} from 'react-native';
import Main from './app/components/Main';
import {configureStore} from './app/store';
export default class App extends Component<Props> {
render() {
return (
<Provider store={configureStore()}>
<Main/>
</Provider>
);
}
}
const styles = StyleSheet.create({
container: {
flex: 1,
justifyContent: 'center',
alignItems: 'center',
backgroundColor: '#F5FCFF',
},
welcome: {
fontSize: 20,
textAlign: 'center',
margin: 10,
},
instructions: {
textAlign: 'center',
color: '#333333',
marginBottom: 5,
},
});
但我想,redux-persist
中有新的更新。所以,使用这段代码我得到如下错误。
据我了解,在新的更新中,不再有autoRehydrate
。但是我无法处理,如何更新代码以便它适用于新版本。你能帮我吗?