React Native doesn't re-render when re-opening app

Viewed 348

I have a functional component in my react native app that has an event listener watching the app state in order to clear out a cache when the app is closed. This works as expected, and I have logic written in a useEffect block to add/remove this event listener when the app is closed.

The functionality works perfectly when the user either navigates elsewhere in the app or closes the app, but when the app is re-opened after closing (not fully shutting down the app, just moving to a different app) the page is not re-rendered and so the event listener is not re-added.

I've attached the code in my useEffect below.

useEffect(() => {
  if (!listenerRef.current) {
    toggleEventListener(true);
  }
  return () => {
    toggleEventListener(false);
  };
}, []);
1 Answers
Related