首页 > 解决方案 > 未定义不是对象(评估'_this.ref.limitToLast')错误

问题描述

我的反应本机代码面临一些问题,如下所示,我无法弄清楚为什么会继续发生这种情况。我确信错误来自refOn我的 firebaseSDK 文件中的方法。

refOn = callback => {
    this.ref
      .limitToLast(20)
      .on('child_added', snapshot => callback(this.parse(snapshot)));
  }

当我导航到我的聊天页面时,componentDidMount会调用该方法,然后调用该refOn方法来查看所有先前发送的消息。

componentDidMount() {
        firebaseSDK.refOn(message => 
          this.setState(previousState => ({
            messages: GiftedChat.append(previousState.messages, message),
            })
          )
        );
      }

我得到的错误是:

TypeError: TypeError: undefined is not an object (evaluating '_this.ref.limitToLast')

基本上它是来自 https://blog.jscrambler.com/build-a-chat-app-with-firebase-and-react-native/的聊天应用程序。

没有该refOn方法,错误来自该componentDidMount()方法给我同样的错误,但使用该refOn方法,现在错误来自这个。

编辑:所有文件的 Git 存储库 https://github.com/KrishnaRamdin/ReactNative_Chat-Room

标签: reactjsreact-nativefirebase-realtime-database

解决方案


推荐阅读