Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to pop to the previous screen with params?

I'm on screen A which has current state of {key:'value'} , I navigated to screen B

now I'm trying to pop from screen B to screen A again , but I don't want to lose the current state in screen A {key:'value'}

some solution is to save data in the AsynStorage , and retrive it when coming back to screen A , but that's not a good practice

.pop() do it , but what if I need to go back with additional params ?

Navigation.pop(this.props.componentId , {
                               passProps: {
                                       data : 'current',
                                       more : 'just-example'
                                     }});

the above code , did not work

any suggestions ?

I don't use any state management tool like Redux/Mobx ..

like image 355
Ahmed Mohsen Avatar asked Jan 26 '23 09:01

Ahmed Mohsen


1 Answers

I found a good solution is to send a callback function with the params

in screen A

  getback(success)
  {
      alert(success);
  }

  Navigation.push(this.props.componentId , { component : {
         name : "Payment",
         passProps: {
         subscription : current,
         getback: this.getback
       },
   }});

then in screen B , when you pop to screen A fire the getback function

Navigation.pop(this.props.componentId);
this.props.getback(true);

this worked well with me

like image 197
Ahmed Mohsen Avatar answered Jan 29 '23 14:01

Ahmed Mohsen