React native app, pressing android-phone back-button should refresh previous page or component?

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

Answer

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;};