My first ever question in SOF seems to be a bit silly but let's consider I am new to web development and creating my firsts JavaScript Applications :). I am trying to access the value of a variable to use it when dispatching. The value is the key which I get from Firebase database and I would like to pass the value to my "child" selection in "dispatch" method. This is what I did
export function addUser(name, username, image) {
var lastIndex;
usersRef.limitToLast(1).once("child_added", function(snapshot) {
lastIndex = snapshot.key;
});
return dispatch => usersRef.child(lastIndex).set({"name": name, "username": username, "image": image});
}
lastIndex is the variable that I am trying to access in dispatch but it returns undefined