Pass data between two screens with React Native and TypeScript

Viewed 64

I'm trying to pass data between two different screens

Here is the data:

const [arrange, setArrange] = useState(false); // the clubs arrange state

The state is updating the home screen and arranging it differently based on the 'arrange' value (if true, one way, if false another). I want to update the arrange value on the second screen and send it back to the home screen and see the change.

1 Answers

You can use the call-back function to pass to the next screen like
this.props.navigation.navigate('Screen2',{onBackCallBack:this. onBackCallBack})

this function will be in your Screen 1 and you can do any thing when you back from Screen2
onBackCallBack=()=>{}

while you getting back from Screen 2 you have called this prop like
this.props.navigation.state.params.onBackCallBack()

Related