I've got screen 1 from which I navigate to screen 2 using:
navigation.navigate('Screen2')
From this screen, I would like to go to the previous one, which simple:
navigation.goBack()
However I'm wondering how can I pass some data back to Screen1? Something like wouldn't work navigation.goBack({ myData: 'something' })
so I'm wondering what is the recommended way to do this in general?
You can pass a callback (onSelect) like this:
You can solve it with 2 ways :
1 : Using navigation method
Pass a method when you are calling that screen through navigation :
and when you press back, pass data like
2 : Using redux store
If you are using redux in your application, just update redux store whenever user presses back button, and get store value in previous screen.
if you're using v2 or newer, another possibility is using the
navigate
function, providingkey
/routeName
of the route you're going back to and theparams
. docs: https://reactnavigation.org/docs/en/navigation-actions.html#navigate