diff --git a/docs/next/backhandler.html b/docs/next/backhandler.html index 76ff1b07cc8..4278a3f1a62 100644 --- a/docs/next/backhandler.html +++ b/docs/next/backhandler.html @@ -29,16 +29,30 @@ return false; }); -
Example 2:
+Lifecycle example:
componentDidMount() {
- this.androidBackHandler = BackHandler.addEventListener('hardwareBackPress', () => {
+ BackHandler.addEventListener('hardwareBackPress', this.handleBackPress);
+ }
+
+ componentWillUnmount() {
+ BackHandler.removeEventListener('hardwareBackPress', this.handleBackPress);
+ }
+
+ handleBackPress = () => {
+ this.goBack(); // works best when the goBack is async
+ return true;
+ }
+
+Lifecycle alternative:
+ componentDidMount() {
+ this.backHandler = BackHandler.addEventListener('hardwareBackPress', () => {
this.goBack(); // works best when the goBack is async
return true;
});
}
componentWillUnmount() {
- this.androidBackHandler.remove();
+ this.backHandler.remove();
}