title: Disable back button but when tap twice exit app in react native
body: <p>I am trying to create a small react native app and in that app, I have created some screens. On a particular screen, I want to disable the system back button and I did that but I want to create a logic on that same screen that if the user taps twice then app will be closed.</p>
  <p>My screen</p>
  <pre><code>import React, {Component, useEffect} from 'react';
  import {StyleSheet, Text, View, Button, BackHandler, Alert} from 'react-native';
  
  export default function HomeScreen({navigation}) {
    useEffect(() =&gt; {
      BackHandler.addEventListener('hardwareBackPress', () =&gt; true);
      return () =&gt;
        BackHandler.removeEventListener('hardwareBackPress', () =&gt; true);
    }, []);
  
    return (
      &lt;View style={{flex: 1, alignItems: 'center', justifyContent: 'center'}}&gt;
        &lt;Text&gt;Home Screen&lt;/Text&gt;
        &lt;Button
          title=&quot;Go to Other Screen&quot;
          onPress={() =&gt; navigation.navigate('Employees')}
        /&gt;
      &lt;/View&gt;
    );
  }
  </code></pre>
  <p>But there is one more problem as well, This code is disabling back button on every screen.</p>