title: How to get all documents in a collection in firestore?
body: <p>I am trying to get all documents in my collection but the log return an empty array and i am having an error message that says cannot read property of undefined reading forEach. i have followed the documentation but can't find where the issue is. Can someone help, please?
  The code snippet below is a custom hook i am using it in my index.js as per following. this log return an empty array.</p>
  <pre><code>const { docs } = useFireStore('barbers')
      console.log('docs',docs)
  </code></pre>
  <pre><code>import { useState, useEffect } from &quot;react&quot;;
  import { collection, getDocs, querySnapshot } from &quot;firebase/firestore&quot;; 
  import {db} from '../../../base'
  export const  useFireStore = (mycollection) =&gt; {
     
      const [docs, setdocs] = useState([])
  
      useEffect(() =&gt; {
      
      const  unsub = async () =&gt; {
  
          await getDocs(collection(db,mycollection))
          querySnapshot.forEach((doc) =&gt; {
              let document =[];
              // doc.data() is never undefined for query doc snapshots
              document.push({...doc.data() ,id: doc.id});
              //console.log(doc.id, &quot; =&gt; &quot;, doc.data());
            });
            setdocs(document);
      } 
  
      
        return () =&gt; unsub();
         
        
      }, [mycollection])
      
      return { docs };
    
  }
  </code></pre>