React-native-gifted-chat undefined error displaying messages due to deprecated methods

James Chen
2 min readJul 6, 2023

--

Have you encountered this error?

_reactNative.Keyboard.removeListener is not a function

If you’ve updated to use the latest version of React Native or Expo SDK, you’re going to encounter this error a lot because the Keyboard listener methods have been deprecated. The error should say Keyboard.addListener… does not exist. If this is you, here’s the fix!

Go to /node_modules/react-native-gifted-chat/lib/MessageContainer.js

This is what it should look like, now remove all the lines that start with Keyboard.addListener or Keyboard.removeListener and replace it with the text in the comment:

https://github.com/FaridSafi/react-native-gifted-chat/issues/2090#issuecomment-901812607

Now it should look like

If you run your app again, it should be fixed! You’ll notice the invertible props are not being used, you can just delete that line if you want.

Next, run npx patch-package react-native-gifted-chat

Commit the patch something along the lines of

git commit -am “fixing react native gifted chat deprecated methods”

Shout out to Eric Gutierrez for this fix

Notable links: Github issue, Stackoverflow post

--

--