Created
October 28, 2021 19:43
-
-
Save princefishthrower/5b58245f43e081f2d41d3663ac53a5bd to your computer and use it in GitHub Desktop.
Updated useEffect for KeyboardShift on React Native 0.66 and higher
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
const [didShowListener, setDidShowListener] = useState<EmitterSubscription | null>() | |
const [didHideListener, setDidHideListener] = useState<EmitterSubscription | null>() | |
useEffect(() => { | |
setDidShowListener(Keyboard.addListener('keyboardDidShow', handleKeyboardDidShow)); | |
setDidHideListener(Keyboard.addListener('keyboardDidHide', handleKeyboardDidHide)); | |
return () => { | |
if (didShowListener){ | |
didShowListener.remove(); | |
} | |
if (didHideListener) { | |
didHideListener.remove(); | |
} | |
} | |
}, []) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment