【问题标题】:Listeners Agents Firebase not only in ComponentDidMount Method监听器代理 Firebase 不仅在 ComponentDidMount 方法中
【发布时间】:2018-05-06 07:48:56
【问题描述】:

有没有办法在状态更改后设置数据库代理侦听器?我的意思是通常我们习惯于在componentDidMount 方法上设置它。但我想根据一个州来称呼它。

我希望我的用户获取特定数据的列表,而不是所有节点。该数据不应该直接在应用启动时“监听”,而是在应用进入特定状态之后。

firebase.database().ref("myRef")
    .on("value", (snap)=>{ 
        console.log(snap.val()) 
    }
)

【问题讨论】:

    标签: javascript firebase react-native firebase-realtime-database


    【解决方案1】:

    尝试定义一个函数并在状态发生变化时调用它:

     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
     }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2013-07-12
      • 2018-10-25
      • 2019-05-25
      • 2017-10-03
      • 2019-01-29
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多