这是我来自带有 firebase 的 React 项目的代码,我从早上就陷入了这个问题,请帮助我 plzzz
constructor (){
super()
this.state = {Message : false}
this.Navigate = this.Navigate.bind(this)
CompLoad = true
var i = firebase.auth().currentUser.uid
firebase.database().ref('users/' + i + '/inbox').limitToLast(1)
.on('value' , function (x){
if (CompLoad === false){
var data = x.val()
alert(JSON.stringify(data))
R = 'Inbox'
this.Navigate()
}
if (CompLoad === true){
CompLoad = false
}
})
}
它给了我错误:-
TypeError: Cannot read property 'Navigate' of null
导航功能
Navigate = () => {
this.context.router.history.push('/' + R)
}
如果我用 setState 替换 Navigate
this.setState({
Message : true
})
反应 说:
TypeError: Cannot read property 'setState' of null