Reputation: 442
Currently I'm working in react native, I have two pages A and B, I'm already on A Screen after clicking on continue button I moved on B Screen , there is an back button. now my question is :=> if I click on back Button then I want to pass my Name on previous Screen from state:
Have tried this:
1.this.props.navigation.goBack({'Name':'a'})
2.GoBack=async(data)=>{
if (data !== null) {
this.props.navigation.navigate('A', {
onGoBack: () => this.refresh(),
'Name':'a',
});
}}
3.this.props.navigation.navigate({'Name':'a'})
In This method I'm getting my Name in previous Screen but state is not getting update after refreshing it's showing name.
Upvotes: 0
Views: 2207
Reputation: 442
finally it's working : Thanks everyone :)
this.props.navigation.navigate("A", {
'Name':'a',
onGoBack: () => {
this.refresh()
}
});
Upvotes: 0
Reputation: 5700
Try below code :
this.props.navigation.navigate("A", {
'Name':'a',
onGoBack: () => {
this.refresh()
}
});
And your screen 'A' :
this.props.navigation.state.params.onGoBack();
this.props.navigation.goBack();
Upvotes: 1
Reputation: 279
this.props.navigation.addListener(
'willFocus',
payload => {
this.setState({Name:payload.Name});
}
)
Upvotes: 0