I created this function:
var IDOfUserToKill = 'tralala';
export function getIDOfUserToKill(userID, gameID) {
let path = '/games/' + gameID + '/users/' + userID;
fb.database().ref(path).on('value', snapshot => {
IDOfUserToKill = '';
if (snapshot.val()) {
IDOfUserToKill = snapshot.val().userToKill;
console.log(IDOfUserToKill); // return the good ID
}
});
}
userID = IDOfUserToKill; // return "tralala" and not the good ID
Then I want to use the variable IDOfUserToKill
outside this one. Because if I use IDOfUserToKill
, it returns the value that was defined before the function (tralala) and not the ID.
How to retrieve the content of the variable? (I use React Native).