0

I guess this is not a Firebase question as much as it is a callback syntax question:

I want the function changeName to go to Firebase database and replace the value of "t" with a value that is a child of "t" in the database.

function changeName (t) {
    return (
        t.replace(t, firebase.database().ref(`langs/${t}`).once('value', snap => snap.val().name))
    )
}

But I get [object Promise].

The code does work when I put an alert() method inside the snap arrow function, so I know the access to the value is fine. I just couldn't figure out how to get the value as a string of text for the replace() method.

Frank van Puffelen
  • 565,676
  • 79
  • 828
  • 807

1 Answers1

0

This should work

    function changeName (t) {
        return (
                firebase.database().ref(`langs/${t}`).once('value', snap => {
                t.replace(t, snap.val().name);
            })
            
        )
    }

Arup
  • 131
  • 5