title: React Native BackHandler Not Following State Updates
body: <p>My <code>backAction</code> function that's used in <code>BackHandler</code> event listener, uses a <code>stage</code> state for conditionals, but doesn't follow the state value updates when <code>stage</code> is updated by other components, as it gets stuck on the initial state value. and also return true and false don't do anything.</p>
  <p><strong>Expected Behavior:</strong></p>
  <p>If back button is pressed check current stage:</p>
  <ul>
  <li>If stage value is 1 then use <code>return false</code> to trigger back button default behavior and navigate back to the previous screen (with out the need to use <code>navigation.goBack()</code>).</li>
  <li>If stage value is more that 1 then just decrement the current stage
  value by -1, and <code>return true</code> to stop the event bubbling.</li>
  </ul>
  <p><strong>Current Behavior:</strong></p>
  <p>Once back button is pressed:</p>
  <ul>
  <li>Uses and keeps using on each click <code>stage</code> initial value of 1 even if it's clear that other components changed it and used it's new value.</li>
  <li><code>return false</code> doesn't even trigger the default behavior of the back button.</li>
  </ul>
  <p><strong>Code To Reproduce:</strong></p>
  <pre><code>const [stage, setStage] = useState(1);
  
  const backAction = async () =&gt; {
    console.log(stage); // the bug: stage is always 1
  
    if (stage === 1) {
      console.log(&quot;Going back to previous screen!&quot;);
      return false;
    } else if (stage &gt; 1) {
      console.log(&quot;Setting stage back with -1&quot;);
      await setStage((prevState) =&gt; prevState - 1);
      return true;
    }
  
    return false;
  };
  
  useEffect(() =&gt; {
    BackHandler.addEventListener(&quot;hardwareBackPress&quot;, backAction);
  
    return () =&gt; BackHandler.removeEventListener(&quot;hardwareBackPress&quot;, backAction);
  }, []);
  </code></pre>
  <p><strong>Note:</strong> I've used the documentation pattern of assigning <code>BackHandler.addEventListener</code> to <code>backHandler</code>, and then using it in the events clean up as <code>backHandler.remove()</code>. didn't work either, but removed it here for the sake of simplicity.</p>
  <p>Any help would be much appreciated.</p>