以下是我尝试使用react-native -
为iOS应用做的事情get/fetch
中AysncStorage
列表中的所有项目。这是在componentDidMount()
中完成的。这很好。componentDidMount()
。如何解决这个问题?
答案 0 :(得分:0)
Redux是最好的选择,但有一个肮脏的解决方法如下:
主屏幕
state = { items: [] }
addItemFromChild = (item) => {
this.setState((prevState) => ({ items: [...prevState.items, item] }))
}
goToAddItemScreen = () => {
this.props.navigation.dispatch(NavigationActions.navigate({ routeName: "AddItemScreen", params: { addItemFromChild: this.addItemFromChild } }))
}
AddItemScreen
addItem = (item) => {
this.props.navigation.state.params.addItemFromChild(item)
}