0
如何从AsyncStorage将数据加载到应用程序加载第一页时的reduce store?React Native:从AsyncStorage加载值
我试图调用componentWillMount
中的检查函数。
componentWillMount(){
debugger;
this.check();
}
和在检查我试图从AsyncStorage
取的值,并将其存储到终极版存储对象。
async check(){
await AsyncStorage.getItem('location').then((location) => {
this.props.location[0].city = location;
}
});
this.props.selectLocation(this.props.location);
}
由于它是一个异步函数,我无法得到的值,并将其存储查看终极版selectLocation
行动。
如何正确获取数据并将其存储在组件安装之前?
更新:
在我index.android.js我改变了我的店就是这样,
import { persistStore, autoRehydrate } from 'redux-persist'
import combineReducers from './src/Redux/reducers/combineReducers';
// const store = createStore(combineReducers);
const store = compose(autoRehydrate())(createStore)(combineReducers)
persistStore(store, {storage: AsyncStorage},() => {
console.log('restored');
console.log(store);
})
export default class ReactNavigation extends Component {
render() {
return (
<Provider store = {store}>
<App />
</Provider>
);
}
}
await this.check(); – David