How can I push back to parent screen with parameters?
Navigation.pop(this.props.componentId)
can only close the current screen, but not passing values.
Navigation.push(this.props.componentId, {
component: {
name: 'ParentView',
passProps: {
data: 'values',
}
},
});
can pass values, but create a new ParentView...
Is that any way I can pass back value to parentView, and close current view? Thanks.
You can use this workaround:
Props are immutable but if you pass function, it can be updated.
Example:
ScreenA to ScreenB:
Navigation.push(this.props.componentId, {
component: {
name: 'ScreenB',
passProps: {
thisPro: ((this) => {return this})
}
}
})
On ScreenB, make your update and when you pop on your component, make this:
Navigation.pop(this.props.componentId);
componentWillUnmount() {
//It will update parent's state
this.props.thisPro.setState({data: "values"});
}
Back to your ScreenA, you can access new values with this.state.data
Props should be immutable.
That said, in instances where you need to pass some data to previous screens, a ui store which act a bit as a controller is usually a good way to go. Whether you use redux or MobX or ..., having a connected UI store should apply changes instantly to your mounted screen.
Thanks @peresbri and @NISUSIN , it work for me!!!
Most helpful comment
Props should be immutable.
That said, in instances where you need to pass some data to previous screens, a ui store which act a bit as a controller is usually a good way to go. Whether you use redux or MobX or ..., having a connected UI store should apply changes instantly to your mounted screen.