0

I'm new to React Native, I was trying to use the template literals for my firebase update, but somehow it doesn't work. Did I used in a wrong way? here is my code:

export default function updatefriends(FriendsUID){

    const friendadd = async() =>{

        
        const Uid = firebase.auth().currentUser.uid
        const friendlist = firebase.firestore().collection('users').where(
            "UID", "==", firebase.auth().currentUser.uid).get();
            
        console.log(Uid)
        friendlist.then((querySnapshot) => 

        {querySnapshot.forEach((doc) => {doc.ref.update(

            {'FriendsList.${FriendsUID}':true})
        })
    })
    }

This line having issue:

{'FriendsList.${FriendsUID}':true})

When I push the update, it added "${FriendsUID}" into my database, instead of the actual text.

Chang
  • 77
  • 6

1 Answers1

1

You need to add backticks (`) in order to use template literals. Also since this is a dynamic object key property you have to wrap it in brackets []. Finally the problematic line should be:

{ [`FriendsList.${FriendsUID}`] : true }
fgkolf
  • 910
  • 3
  • 15