reactjs - react where to put the firebase change listener in a component -


i new firebase , trying link in firebase-database. if put following in render function:

let temperature = itemsref.child('current_temperature'); temperature.on("value", function (snapshot) {           mydata = snapshot.val();           console.log('temp', mydata); }); 

the log messages display in console, can't see how display in template. there simple example component of how updated values watcher display in html?

move code componentdidmount lifecycle hook , in place of console.log use binded this.setstate()

componentdidmount() {   let temperature = itemsref.child('current_temperature');   temperature.on("value", (snapshot) => {     mydata = snapshot.val();     this.setstate({       temp: mydata     });   }); } 

Comments

Popular posts from this blog

javascript - Create a stacked percentage column -

Optimising Firebase database by automatically overwriting data -

javascript - Angular UI-Grid customTemplate directive causing rows to load slowly/? -