first time using firebase, i'm creating a blog, when i create a post i'm creating it as:
const postCollection = collection(database, "posts");
const submitPost = async () => {
await addDoc(postCollection, {
title,
body,
comments: [],
liked: false,
user: { name: auth.currentUser.displayName, id: auth.currentUser.uid },
});
};
Below each post i have a comment section, but i'm a bit confused about adding the comments.
I tried this:
const addComment = async (id) => {
const targetPost = doc(database, "posts", id);
await setDoc(targetPost, { ...targetPost, comments: [comment] });
};
But it didn't work. Thanks in advance