Skip to content

Instantly share code, notes, and snippets.

@arminyahya
Created November 1, 2019 07:10
Show Gist options
  • Save arminyahya/559b04797589c1e217094f87c3e56b95 to your computer and use it in GitHub Desktop.
Save arminyahya/559b04797589c1e217094f87c3e56b95 to your computer and use it in GitHub Desktop.
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