I want to check if the user closed the app in less than seconds, and I have found the AppState
to do so, but I can't find a solution to add a timer
Here is my implementation:
useEffect(() => {
const subscription = AppState.addEventListener('change', (nextAppState) => {
if (
appState.current.match(/inactive|background/) &&
nextAppState === 'active'
) {
console.log('Inactive');
}
appState.current = nextAppState;
console.log('AppState:', appState.current);
});
return () => {
subscription?.remove();
};
}, []);