0
この場合、私の状態をどのように初期化するのでしょうか。 基本的に、AsyncStorageからデータを取得し、それをリストとして画面に書きたいと思います。反応ネイティブ状態を初期化するにはどうすればいいですか?
export class History_d extends Component {
constructor(props){
super(props)
this.state = {
stores : ???????????
}
}
componentDidMount() {
AsyncStorage.getAllKeys((err, keys) => {
AsyncStorage.multiGet(keys, (err, stores) => {
this.setState({ stores });
});
});
}
render() {
return (
<View>
{this.state.stores.length && this.state.stores.map(item =>
<Text>{item[0]} {item[1]}</Text>)}
</View>
)
}
}
私の状態を初期化するために、自分のコンストラクタで書くべきことを誰かに説明することはできますか?
ありがとうございました!
if (!this.state.stores)
return <Text>Loading...</Text>;
ボーナス:
は、それが正常に動作しますありがとう! –