user7747472
user7747472

Reputation: 1952

How to pass data from one screen to another in wix react native navigation

I am new to this React native and javascript as a whole. I am trying to pass data from one screen to another using wix react native navigation. Here is my code On screen one

 _gotoAnotherScreen = (screen,data) => {
        this.props.navigator.push({
            screen: screen,
            title: data.title,
            passProps: {
                data: data
            }
        });
    };

And my data is an array

And on the 2nd screen i am trying to catch the value like this

const { params } = this.props.navigator;
 console.log(params);

This is saying undefined

Can anyone please tell me how i can catch the data.

I tried to follow this thread , Passing Data Using React-Native Navigation But those ansers giving me error saying trying to get property of undefined.

Any help please . Thank you

Upvotes: 2

Views: 2443

Answers (2)

Aung Myat Hein
Aung Myat Hein

Reputation: 4178

At First screen. Pass param like this.

 this.props.navigation.navigate({
            screen: "SecondScreen",
            params: { data: data }
 });

At second screen, You can catch param value like this.

componentDidMount() {
  const {data} = this.props.navigation.state.params;
}

Upvotes: 1

user7747472
user7747472

Reputation: 1952

After lot of looking here and there and some trial and error i found out.

it can used just like any other object. like this this.props.data

Upvotes: 1

Related Questions