'How to convert this firebase code into its latest syntax in React.js?

useEffect(() => {
  db.collection('posts').onSnapshot((snapshot) => {
    setPosts(snapshot.docs.map((doc) => doc.data()));
  });
}, []);

I have been trying to use this code in react but I was unable to do it.



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source