【发布时间】:2018-06-16 18:27:08
【问题描述】:
只是一个简单的问题,我一直在尝试使用 AsyncStorage 列出项目,但我就是想不通。我曾经根据网上的一些博客尝试过一些尝试,但它不起作用。所以,我在这里遇到了,希望有人能帮助我。
这是我的代码:
constructor(props) {
super(props);
this.state = {
myKey: []
}
}
async getKey() {
try {
const value = await AsyncStorage.getItem('@MySuperStore:key');
this.setState({myKey: value});
} catch (error) {
console.log("Error retrieving data" + error);
}
}
async saveKey(value) {
try {
await AsyncStorage.setItem('@MySuperStore:key', value);
} catch (error) {
console.log("Error saving data" + error);
}
}
更新:
<TextInput
style={styles.formInput}
placeholder="Enter key you want to save!" // This is the component where I think the warning came from.
value={this.state.myKey}
onChangeText={(value) => this.saveKey(value)}
/>
【问题讨论】:
标签: javascript android react-native asynchronous