I was facing a similar issue, so here is how I solved it by going more into details.
Option one is to navigate back to parent with parameters, just define a callback function in it like this in parent component:
updateData = data => {
console.log(data);
alert("come back status: " + data);
// some other stuff
};
and navigate to the child:
onPress = () => {
this.props.navigation.navigate("ParentScreen", {
name: "from parent",
updateData: this.updateData
});
};
Now in the child it can be called:
this.props.navigation.state.params.updateData(status);
this.props.navigation.goBack();
Option two. In order to get data from any component, as the other answer explained, AsyncStorage can be used either synchronously or not.
Once data is saved it can be used anywhere.
// to get
AsyncStorage.getItem("@item")
.then(item => {
item = JSON.parse(item);
this.setState({ mystate: item });
})
.done();
// to set
AsyncStorage.setItem("@item", JSON.stringify(someData));
or either use an async function to make it self-update when it gets new value doing like so.
this.state = { item: this.dataUpdate() };
async function dataUpdate() {
try {
let item = await AsyncStorage.getItem("@item");
return item;
} catch (e) {
console.log(e.message);
}
}
See the AsyncStorage docs for more details.