Created
November 1, 2019 07:10
-
-
Save arminyahya/559b04797589c1e217094f87c3e56b95 to your computer and use it in GitHub Desktop.
This file contains hidden or 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 { useEffect, useRef } from 'react'; | |
const ScreenFocusHook = (navigation) => { | |
const _didFocusSubscription = useRef(); | |
const callBack = useRef(); | |
useEffect(() => { | |
_didFocusSubscription.current = navigation.addListener( | |
'didFocus', | |
payload => { | |
console.log('focus'); | |
callBack.current() | |
} | |
); | |
return () => { | |
_didFocusSubscription.current && _didFocusSubscription.current.remove(); | |
} | |
}, []); | |
const setCallBack = cb => { | |
callBack.current = cb | |
} | |
return [ | |
setCallBack | |
] | |
} | |
export default ScreenFocusHook; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment