0
votes

I am using react-native-router-flux in my application.

-I am using a parameter at my first screen and then i navigate to second screen.

-On the second screen i am updating that parameter which was used at my first screen.

-I want it to be updated when i navigate back to that screen (first screen).

How can i implement this functionality.

Thank You

2
Sharing data between views... Maybe using Redux ? - Vinzzz
@Vinzzz I am not using Redux, then? - Kailash
what have you tried so far ? - Vinzzz
@Vinzzz Can you please suggest, what should i do? - Kailash

2 Answers

0
votes

@Vinzzz is right best solution is to use redux. But here how you can make this work without it.

When you navigate to another view you call action.OTHER_VIEW()

You can pass parameters to this function, which will be available via props in the component corresponding to your key : "OTHER_VIEW"

Here an example :

routeA.js

constructor(props){
  super(props);
  var _data = this.props.dataFromRouteB || "";
  this.state = {
    data : _data
  };
}

onPress(){
  action.ROUTE_B({dataFromRouteA: this.state.data}); // navigate to route B
}

render(){
  const {data} = {...this.state};
  return(
    <View>
      <Text>{data}</Text>
      <Button title="go to route B" onPress={()=> this.onPress()} />
    </View>
  );
}

routeB.js

componentDidMount(){
  var a = this.props.dataFromRouteA; // a = ""
  a = "hello";
  action.ROUTE_A({dataFromRouteB:a}); // navigate to ROUTE_A , data will be available via  props
}
0
votes

I Solved this Issue without using Redux.

Put the api calling statement of Screen First in a method(on First Screen) and passed it to second screen. On the second screen i called this method inside componentWillUnmount(). Its updating my first screen as i will be going back from screen second.