Make request when returning to the previous scene in react-native

0

I'm using react-native-router-flux for routes and scenes.

I have scenes A and B, on screen I make a request GET in an API in the componentWillMount() function and display the information. On screen B I have a form and a button to save and return to scene A using Actions.pop() . I would like, on returning to scene A, to make a new request GET to the API to bring the new information.

I tried to use Actions.pop() and Actions.refresh() , I did several other tests and I did not succeed. I saw in another post a suggestion to pass the function that makes the request via props to scene B and execute it before returning to scene A, but also did not work. The latter seemed to me the best solution.

I would like to know a way to resolve this.

    
asked by anonymous 11.07.2017 / 22:58

1 answer

0

I solved this problem by passing a props to scene A in the Actions.pop () function of scene B, and in scene A I implemented the componentWillReceiveProps () method to call the API if I received a props.

It looks like this:

Dinner A

componentWillReceiveProps(nextProps) {
  if (nextProps !== this.props) {
    this.getData();
  }
}

Dinner B

Actions.pop({ refresh: {update: true} });
    
12.07.2017 / 15:21