Last active
September 15, 2022 17:57
-
-
Save alanhchoi/e785757ba6521a32b6dd609031ecc219 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { useCallback } from 'react'; | |
import { useNavigation, NavigationProp, useFocusEffect } from '@react-navigation/native'; | |
function delay(ms: number) { | |
return new Promise((resolve) => setTimeout(resolve, ms)); | |
} | |
function ScreenA() { | |
const navigation = useNavigation<NavigationProp<any>>(); | |
useFocusEffect( | |
useCallback(() => { | |
const timeoutId = setTimeout(() => { | |
// Schedule a navigation 5 seconds after this screen is focused. | |
navigation.navigate('ScreenB'); | |
}, 5000); | |
return () => { | |
// If user leaves the screen, cancel the scheduled navigation. | |
clearTimeout(timeoutId); | |
}; | |
}, [navigation]) | |
); | |
return <></>; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment