Here is what I am trying to do for an iOS app using react-native -
get/fetch
from AysncStorage
. This is done in the componentDidMount()
. This works fine.componentDidMount()
is not called.How can this issue be solved?
Redux is the best option but a dirty workaround is the following:
Home screen
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)
}