0

So , I'm trying to populate a state array after getting the data from firestre

useEffect(() => {
    getDocs(postsRef)

      .then((e) => {
        e.docs.forEach((event) => {
          console.log(event.data());
          setPosts([...posts, event.data()]);
          console.log(posts);
        });
      })

      .catch((err) => console.log(err));`

The first log gives me the data , the second one should give me the fully populated array but instead I get an empty array , any solutions ?

Doug Stevenson
  • 297,357
  • 32
  • 422
  • 441

0 Answers0