reactjs - 未定义不是对象(评估'_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
解决方案
推荐阅读
- c# - Html.listboxfor() 如何捕获更改/添加项目的事件 - Jquery MVC (C#)
- python - 如何在 iframe 中使用 python-selenium 获取无头浏览器的全页截图?
- xamarin - 对象引用未设置为 httpclient.defaultrequestheaders.accept.add android xamarin 中的对象实例
- c# - 如何在具有动态条件的 linq 查询中使用 order by 子句?
- sass - 根据使用的 sass mixin 将生成的 css 代码从 scss 源拆分为多个 css 文件
- ajax - 流程图上的 Json 返回结果图
- url - 在 URL power Bi 中应用过滤器
- go - 如何返回第一个http响应以回答
- google-cloud-platform - Stackdriver IoT 设备监控
- angular - 我想让这个角度代码返回多个结果而不是一个