So I have some code here, which is supposed to automatically run whenever the firebase server updates:
//Whenever the firebase database changes, it runs this method
useEffect(() => {
db.collection("posts").orderBy("timestamp", "desc").onSnapshot((snapshot) =>
//Loops through all the posts and adds the data into an array
setPosts(snapshot.docs.map((doc) => doc.data()))
);
}, []);
But how does it know that the database updated? I thought that useEffect only ran whenever the screen rendered, so how does it know to run when the database gets updated?