loading...

re: The Firestore Tutorial for 2020: Learn by Example VIEW POST

FULL DISCUSSION
 

This is good but in Unsubscribing from a collection with unsubscribe(), you forgot to return the unsubscribe function that should have done the actual unsubscription. It should be:

function App() {
  const [books, setBooks] = React.useState([]);

  React.useEffect(() => {
    const unsubscribe = firebase
      .firestore()
      .collection("books")
      .onSnapshot((snapshot) => {
        const data = snapshot.docs.map((doc) => ({
          id: doc.id,
          ...doc.data(),
        }));
        setBooks(data);
      });
+
+   return unsubscribe
  }, []);

  return books.map(book => <BookList key={book.id} book={book} />)
}
 

I mentioned it, but didn't include it. Thanks, fixed.

 

You are welcome 😉😉😉

Code of Conduct Report abuse