Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to pass values to other component in React-Native-Router-Flux?

My code is:

... <Router>  <Scene key="com1" component={Com1} initial/> <Scene key="com2" component={Com2}/> </Router> ... com1.js ... onPress={Actions.com2} 

I changed com1 to com2.

But I need to pass values for the inputbox of Com1 to Com2.

How can I do that?

like image 563
Eric Chan Avatar asked Sep 21 '16 08:09

Eric Chan


People also ask

How do I send data from one component to another in react router?

First, you'll need to create two components, one parent and one child. Next, you'll import the child component in the parent component and return it. Then you'll create a function and a button to trigger that function. Also, you'll create a state using the useState Hook to manage the data.


2 Answers

You can pass data like this:

Actions.com2 ({text: 'Hello World'})

You can recover your data in com2 like this:

this.props.text

You can go to the next tutorial for more information:

https://github.com/aksonov/react-native-router-flux/blob/master/docs/v3/MINI_TUTORIAL.md

like image 68
Alexandre Teixeira Avatar answered Sep 23 '22 17:09

Alexandre Teixeira


In addition to that, (and for those in the comments who said it didn't work) you may want to try below. When you pass the

Actions.com2({text : 'Hello World'}); 

Com2 should pass 'props'

const Com2 = (props) => {    return ( <View ...     {props.text}    ... /> ); 
like image 23
user2552155 Avatar answered Sep 22 '22 17:09

user2552155