I would like to store and use the value of a snap from reading data of a database outside the function. I have tried to store it in a value but a get an undefined in the console
import React, {Component} from 'react';
import {
View,
} from 'react-native';
import firebase from 'firebase'
export default class test extends Component {
constructor() {
super();
}
componentWillMount() {
let user;
firebase.database().ref('/Users/' + firebase.auth().currentUser.uid).on('value', function (snap) {
console.log(snap); // good response printed here
user = snap
})
console.log(user)
// use the value if different ways
}
render() {
return <View/>;
}
}
expected to get the user information printed I currently get undefined