score:0

as terrance suggested. you can use a callback in the props and fire it before pop back to the previous page

answer source: react native pass properties on navigator pop

score:0

i was working on similar thing which i wan't to poptotop and pass some params when i came back to top of the stack.

here how i did it in react navigation 5 :-

props.navigation.reset({ // i did reset my stack using navigation.reset() instead of using poptotop
      index: 0,
      routes: [
        {
          name: "home", //name of screen which you wan't to come back to it
          params: { isdialogopen: true }, // params you wanna pass to the screen
        },
      ],
    });

score:1

i have been working on this and i achieved with react-navigation.

basically, your component a will send to component b the navigation state of component a. so, for b point of view it will be the prevstate before stacking b component.

so when component b navigates "back" to component a using the previous navigation state it was like your navigation state never changed and now you could use the second parameter of navigate to send params back to component a.

this simple example illustrate this practice and i think it is totally valid and no asyncstorage usage.

// in component a use a custom prevstate when goes to component b
const { navigation } = this.props;

navigation.navigate('componentb', { prevstate: navigation.state });
// in component b use this custom goback to "pop" to last screen
function goback(data) {
  const { navigation } = this.props;

  const { routename, key } = navigation.getparam('prevstate');

  navigation.navigate({ routename, key, params: data });
}
// and finally in component a again you could get data like this
function getdatafromcomponentb() {
  const { navigation } = this.props;

  // it is null if no parameters are specified!
  return navigation.state.params;
}

score:7

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


Related Query

More Query from same tag