我想在设置数据时立即从 asyncstorage 做出响应,但我似乎找不到方法这是我的代码
我的列表项 onpress => onLearnMore
onLearnMore = (rowData) => {
this.setState({name:rowData.name}),
this.setState({email:rowData.email}),
this.setState({phone:rowData.phone}),
this.setState({street:rowData.location.street}),
this.setState({city:rowData.location.city}),
this.setState({state:rowData.location.state}),
this.setState({postcode:rowData.location.postcode}),
this.saveData();
//this.props.navigation.navigate('Details', { ...rowData });
};
saveData 将项目设置为 asyncstorage
saveData(){
let data = {
name: this.state.name,
email: this.state.email,
phone: this.state.phone,
street: this.state.street,
city: this.state.city,
state: this.state.state,
postcode: this.state.postcode,
}
AsyncStorage.setItem('data',JSON.stringify(data));
this.previewData();
}
这是我的预览数据
previewData = async () =>{
try{
let datachecker = await AsyncStorage.getItem('data');
let parsed = JSON.parse(datachecker);
alert(parsed.name);
}catch(error){
alert(error);
}
}
但是显示设置为 asyncstorage 的项目的警报不会立即同步。我需要预览两次才能获得与设置状态属性相同的结果
更新错误情况我发现当您将数据设置为保存到异步存储中时,它可以立即同步,有没有办法修复它?
我很抱歉英语不好