Skip to content

Instantly share code, notes, and snippets.

@EduVencovsky
Last active November 8, 2019 01:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save EduVencovsky/aff5741c9f0cf322116ea683d38101b7 to your computer and use it in GitHub Desktop.
Save EduVencovsky/aff5741c9f0cf322116ea683d38101b7 to your computer and use it in GitHub Desktop.
React Hooks to listen to navigation didFocus event
import { useState, useEffect, useRef } from 'react'
export const useNavigationFocusChanged = (navigation, event) => {
const [focus, setFocus] = useState(false)
const listener = useRef(null)
useEffect(() => {
const changeFocus = () => {
setFocus(prev => !prev)
}
listener.current = navigation.addListener(event, changeFocus)
return () => listener.remove()
}, [navigation, event])
return focus
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment