0
我想知道如何在這種情況下初始化我的狀態: Basicaly,我想從AsyncStorage獲取數據並將它作爲列表寫入我的屏幕。如何初始化我的react-native狀態?
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>
)
}
}
有人能解釋我應該在我的構造函數中寫入來初始化我的狀態嗎?
謝謝!
謝謝你,它工作正常! –