0

in my next 13 app i'm using dynamic route and fetching firestore data. when i'm routing i'm passing the doc id and fetch the doc with that id. the fetching part is working but the issue is when i try to update the usesetate object it's not updating at all.

in my dynamic page

const [datas, setDatas] = useState({});

const getData = async () => {
    const docRef = doc(db, "livingPosts", homeid);
    const docSnap = await getDoc(docRef);
    setDatas(docSnap.data());

    console.log(datas); // returns undefined
    console.log(docSnap.data()); // returns the data
  };

  useEffect(() => {
    getData();
  }, []);

why is it not updating?

Mohammed Bekele
  • 727
  • 1
  • 9
  • 25
  • @David yes but it is infinitely updating and calling firestore – Mohammed Bekele May 15 '23 at 12:19
  • 2
    That sounds like a separate issue, potentially with different code than what's shown here. The question asked about the code shown is clearly just an incorrect expectation. State is being updated, it's just happening asynchronously. – David May 15 '23 at 12:24

0 Answers0