useDocument().value is always undefined
#1309
-
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 1 reply
-
It seems like someone already had this "issue" (I don't know for sure that it's a bug) in the past : #1268 |
Beta Was this translation helpful? Give feedback.
-
The problem here is that composables are not being used correctly. I recommend you to give these a read:
In your code, if you only want to get the data once, you can use firebase directly with <script setup lang="ts">
const db = useFirestore();
const roomDoc = computed(() => doc(db, "rooms", roomId));
const roomDocRef = useDocument<Room>(roomDoc);
// or const { data: roomDocRef, pending, error } = ...
</script> You have more examples in docs. Note that the value of the data is initially undefined while it's being retrieved but it will update as soon as it arrives. Following the TS typings should also help you see the possible values. |
Beta Was this translation helpful? Give feedback.
The problem here is that composables are not being used correctly. I recommend you to give these a read:
In your code, if you only want to get the data once, you can use firebase directly with
getDoc()
. Otherwise the code you are writing should be within ascript setup
(like other reactivity api):You have more examples in docs.
Note…