有没有办法在状态更改后设置数据库代理监听器?我的意思是通常我们过去常常在 componentDidMount
方法上设置它。但我想根据状态来调用它。
我希望我的用户获得特定数据的列表,而不是所有节点。该数据不应该直接在应用启动时“监听”,而是在应用进入特定状态后“监听”。
firebase.database().ref("myRef")
.on("value", (snap)=>{
console.log(snap.val())
}
)
最佳答案
尝试定义一个函数并在状态发生变化时调用它,例如:
functionForstateChange(){
//call this function when you want to change your state.
//setState here and make your required state changes if you need.
this.functionForDatabase(); //call the function here
}
functionForDatabase(){
//set your required database code here
}
关于javascript - 监听器代理 Firebase 不仅在 ComponentDidMount 方法中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50197406/