AppState Listener Cleanup Bug
Spot the AppState subscription cleanup mistake in a React Native useEffect hook.
Codejavascript
import { useEffect } from 'react';
import { AppState } from 'react-native';
function useAppActive(onActive) {
useEffect(() => {
const handler = (state) => {
if (state === 'active') onActive();
};
AppState.addEventListener('change', handler);
return () => {
AppState.removeEventListener('change', handler);
};
}, [onActive]);
}What is the bug in this AppState lifecycle code?