【发布时间】:2019-10-03 02:58:23
【问题描述】:
当我的 firebase 数据库更新时,我试图在我的 React 网络应用程序中创建一个事件。
import fire from '../../config/Fire';
....
componentDidMount = () => {
let self = this
let database = fire.database().ref();
let userId = this.state.userId
database.onUpdate(event => {
console.log('eve', event)
})
}
在我的componentDidMount 中,我只是简单地尝试控制台记录它以查看它是否有效,但我收到一个错误:TypeError: database.onUpdate is not a function
我关注了这个页面:https://firebase.google.com/docs/functions/database-events?hl=en
但它并不完全适用于 React。
我想知道我必须如何使用它。
编辑
fire.js
import firebase from 'firebase';
const fire = firebase.initializeApp(config);
export default fire;
我的配置包含 API 密钥。
【问题讨论】:
-
您能分享一下
config/Fire中的内容吗?fire到底是什么? -
@HristoEftimov 我编辑了我的问题。
fire.js看起来像这样。