I am making a login button with firebase authentication that references my firebase realtime database in the promise. When I try to lift that data to change component state, it becomes null.
I tried a simpler approach where I declare a variable outside the firebase reference, then try to set that variable within the function.
I also tried setting "that" as an empty array variable, then accessing it as an array.
I tried setting "that" to this.state.ign, but when I try to access the data I need, it becomes null
**edit - I also thought it was an asynchronous issue, so I used a setTimeout 15000 to allow 15 seconds to go by before trying to console.log outside of the firebase reference.
var that = this;
firebase.database().ref("users/" + this.state.userid).on("value", function (snapshot) {
var userIGN = (snapshot.val().ign);
console.log(userIGN); // WORKS - gives ign from database
that.setState({ ign: userIGN }); // WORKS - sets that.state.ign to ign from database
console.log(that.state.ign); // WORKS - gives ign from that.state
})
console.log(that); // WORKS - shows object that has state with ign
console.log(that.state); // FAIL - shows state object, but ign is null now?!
The second console.log(that.state.ign) should show the data point from the firebase reference