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