Mahmoud Ebada
Mahmoud Ebada

Reputation: 31

React native populate data after navigator.pop()

I need your help I've main component that contains ListView with add button. when user press add button it navigates him to add form. then user fills the form and press save button if save process success then component run navigator.pop() to go back to main component but ListView still dosn't update it's content how to resolve this issue? Thanks

Upvotes: 1

Views: 297

Answers (1)

ansel.baikal
ansel.baikal

Reputation: 11

You can add a callback function to the navigator, when you push a component to the navigator:

navigator.push({
  ....
  callBack: your callback function
  ....
})

Then set the callback function to update the ListView:

your callback funtion(your new data){
  ....
  this.list=this.list.cloneWithRows(your new data);
  ....
}

Before running navigator.pop(), you can all the callBack function to update the destination ListView with new data:

 ....
 this.props.route.callBack(your new data);
 this.props.navigator.pop();
 ....

Hope this will help you.

Upvotes: 1

Related Questions