我正在将redux-persist添加到我的React Native应用程序中,并且在运行persistStore
后,它不会复制保存应用程序场景的状态的一部分。为什么persistStore
放弃我国家的这一部分?
具体来说,我正在使用NavigationExperimental并向州添加不同的路由。在给定路线中,键存在,但不存在保持场景的组件。
以下是发生这种情况的代码:
import React, { Component } from 'react';
import { Text, AsyncStorage } from 'react-native';
import { Provider } from 'react-redux';
import { persistStore } from 'redux-persist';
import firebase from 'firebase';
import store from '../reducers/store.js';
import Container from './container.js';
//Import API keys
import firebaseConfig from '../../api_keys.js';
export default class Index extends Component {
constructor() {
super();
this.state = { rehydrated: false };
}
componentWillMount() {
firebase.initializeApp(firebaseConfig);
// store.getState() contains scenes
persistStore(store, { storage: AsyncStorage }, () => {
// store.getState() does not contain scenes
this.setState({ rehydrated: true });
});
}
render() {
console.log('rehydrated is: ', this.state.rehydrated);
if (!this.state.rehydrated) {
return <Text>Loading...</Text>;
}
return (
<Provider store={store}>
<Container />
</Provider>
);
}
}
&#13;
以下是我创建商店的相关代码。
const store = createStore(
reducer,
INITIAL_STATE,
compose(
applyMiddleware(thunkMiddleware),
autoRehydrate()
)
);
export default store;
&#13;