Request when returning to previous scene in React-Native

Asked

Viewed 605 times

0

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

I got scenes A and B on screen GET in an API in function componentWillMount() and display the information. On screen B I have a form and button to save and return to scene A using Actions.pop(). I would like a new requisition to be made when I return to scene A GET to the API to bring the new information.

I tried to use Actions.pop() and Actions.refresh(), I did several other tests and failed. I saw in another post a suggestion to pass the function that makes the request via props to scene B and run it before going back to scene A, but it didn’t work either. This last one seemed the best solution.

I’d like to know a way to fix that.

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 make the call in the API if you receive a props.

Stayed like this:

Scene A

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

Scene B

Actions.pop({ refresh: {update: true} });

Browser other questions tagged

You are not signed in. Login or sign up in order to post.