2

I'm using a stack navigator and on

<HeaderBackButton onPress={_ => navigation.goBack(null)} 

I want to destroy current screen, I've seen other replacements like using .replace instead of .navigate but I want to do such thing on .goBack.

SAQ
  • 55
  • 10

1 Answers1

0

You can try this way:

componentDidMount() {
    this.backHandler = BackHandler.addEventListener('hardwareBackPress', this.handleBackPress);
  }

  componentWillUnmount() {
    this.backHandler.remove()
  }

  handleBackPress = () => {
    this.goBack(); // works best when the goBack is async
    return true;
  }
anis programmer
  • 989
  • 1
  • 10
  • 25