Firebase with React-native getting error on updating document

Viewed 324

I'm trying to make simple crud application but I'm getting this error while updating doc: [Unhandled promise rejection: TypeError: t is not an Object. (evaluating '"_delegate" in t')]

Here is following code what I do:

  //update user
  const updateUser = async (id, age) => {
    const newFields = {age: age + 1};
    const userDoc = doc(usersRef, id)
    await updateDoc(id, newFields).then(console.log('updated succesfully'))
  };
 //jsx
 {users.map((user) => {
        return (
          <View key={user.name} style={{ width: "30%", marginLeft: "35%", marginBottom: 20 }}>
            <Text>name: {user.name}</Text>
            <Text>age: {user.age}</Text>
            <Button
              onPress={() => updateUser(user.id, user.age)}
              title="increase age"
            />
          </View>
        );
 })}

thanks.

1 Answers

change await updateDoc(id, newFields).then(console.log('updated succesfully')) into await updateDoc(userDoc, newFields).then(console.log('updated succesfully')) basically updateDoc is receiving an id instead of a reference in your code

Related