Firestore getDoc() not saving on useState() hook in reactjs

Viewed 25

I'm trying to get a doc value from firebase using the getDoc() method. It's working. But can't save on useState() hook in ReactJS

Here is my code:

const [post, setPost] = React.useState(null);

    React.useEffect(() => {
        const fetchPost = async () => {
            const docSnap = await getDoc(doc(db, "posts", id));
            setPost(docSnap.data())
        }

        return () => fetchPost();
    }, []);
0 Answers
Related