Skip to content

Commit

Permalink
Android Back Handler Documentation Example
Browse files Browse the repository at this point in the history
Adding second example for using the Android Back Handler appropriately with the react component lifecycle.
  • Loading branch information
kstolte authored May 3, 2018
1 parent eb33e69 commit 9b67096
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions docs/backhandler.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,21 @@ BackHandler.addEventListener('hardwareBackPress', function() {
});
```

Example 2:

```javascript
componentDidMount() {
this.androidBackHandler = BackHandler.addEventListener('hardwareBackPress', () => {
this.goBack(); // works best when the goBack is async
return true;
});
}

componentWillUnmount() {
this.androidBackHandler.remove();
}
```

### Methods

* [`exitApp`](backhandler.md#exitapp)
Expand Down

0 comments on commit 9b67096

Please sign in to comment.