Skip to content

New (apparently with React Native 0.66): undefined is not a function #9

Description

@princefishthrower

Haven't seen this until upgrading to React Native 0.66. This is because react native has removed the removeAllListeners from Keyboard: see here

so the effect:

useEffect(() => {
    Keyboard.addListener('keyboardDidShow', handleKeyboardDidShow);
    Keyboard.addListener('keyboardDidHide', handleKeyboardDidHide);
    return () => {
      Keyboard.removeAllListeners('keyboardDidShow');
      Keyboard.removeAllListeners('keyboardDidHide');
    }
  }, [])

should now become:

useEffect(() => {
    setDidShowListener(Keyboard.addListener('keyboardDidShow', handleKeyboardDidShow));
    setDidHideListener(Keyboard.addListener('keyboardDidHide', handleKeyboardDidHide));
    return () => {
      if (didShowListener){
        didShowListener.remove();
      }
      if (didHideListener) {
        didHideListener.remove();
      }
    }
  }, [])

Edit: this didn't actually solve the mysterious error. I still get TypeError: undefined is not a function - tried ErrorBoundary, try / catch in every function of the component, can't find where it's coming from 🤷

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions