I have an html element that needs to updated every time there is a change in Firebase. What I've done so far is this implement this particular function:
componentWillMount() {
var that = this;
var updateDb = firebase.database().ref("currentToken");
updateDb.on("value", function(snapshot) {
that.setState({ currentToken: snapshot.val() });
});
console.log(that.state.currentToken);
document.getElementById("tokenField").innerHTML = "Current Token: " + that.state.currentToken;
}
What is the proper way to update a variable in my app whenever there is a change in Firebase? Kindly give any suggestion to improve my coding as I'm a beginner.