user6889084
user6889084

Reputation:

React Native: passing values between screen not working

I've two pages: Page1: Two Variables CUR1:

render() {
  const { navigation } = this.props;
  const cur1 = navigation.getParam('cur1', 'ABC');

Page2:

<Button badge rounded light style={styles.ok} onPress={() =>navigate('Home', {cur1:this.state.cur1})} >
  <Text style={styles.oks}>OK</Text>
</Button>

On double checking this.state.cur1 is not empty, but after redirection to Page1 navigation.getParam shows default value

Upvotes: 0

Views: 42

Answers (2)

Deepak
Deepak

Reputation: 1433

You can send data to other screen by using following code

 <Button 
    title="button"
    onPress={() => { this.props.navigation.navigate('Page2', {
                    letter: 'A'
    });}}
  />

Receive data in page 2 like below,

const { params } = this.props.navigation.state;
this.letter = params ? params.letter : null;

Upvotes: 1

Sukesh Hublikar
Sukesh Hublikar

Reputation: 116

You need to pass through params , Below is the example.

navigate("Home",{},
  {
    type: "Navigate",
    routeName: "SecondView",
    params: {cur1:this.state.cur1
  }

Upvotes: 0

Related Questions