1

I am using react-navigation 5 in my react-native app. Where i have two components named A and B(forexample). From A component i can goto B component and from B component i can goto A component and can refresh component A. But when i press android-system back-button which is available below on android phone i cant refresh previous component(A).

Example code:

Class A extend React.component{
   componentdidmount = () => {
      //some api call
   }
render(){
   return(
     <Button onPress={this.props.navigation.push("B")}> Goto B Component</Button>
   );
}
}

Class B extend React.component{
   componentdidmount = () => {
      //some api call
   }
render(){
   return(
     <Button onPress={this.props.navigation.push("A")}> Goto A Component</Button>
   );
}
}

How to refresh previous component when android-system back-button pressed? Thanks

user999
  • 17
  • 6
  • Hi, https://stackoverflow.com/questions/44223727/react-navigation-goback-and-update-parent-state you have the same problem, good luck – tycyly Apr 15 '21 at 07:48
  • With android system navigation button(available on every android phone) i want to update previous component. Provided link was not helpful. – user999 Apr 15 '21 at 07:53

1 Answers1

0

try this

import { BackHandler } from "react-native";         

componentDidMount()
  {BackHandler.addEventListener('hardwareBackPress',this.handleBackButtonClick);}

componentWillUnmount()
  {BackHandler.removeEventListener('hardwareBackPress',this.handleBackButtonClick);}    
    
handleBackButtonClick = () => {this.props.navigation.push("B"); return true;};
Zaid
  • 34
  • 1