title: Setting state before render with ref to firestore
body: <p>I am working through a simple logical problem, but I cannot seem to have things work smoothly. Let me share my most convincing code experiment and then I'll share some thoughts.</p>
  <pre><code>useEffect(() =&gt; {
      firebase
          .firestore()
          .collection(&quot;someCollection&quot;)
          .orderBy(&quot;date&quot;, &quot;desc&quot;)
          .onSnapshot(docs =&gt; {
              let documents = []
              if (canGetUpdatesFromFirestore.current) {
                  docs.forEach((doc) =&gt; {
                      documents.push(doc.data())
                  })
  
                  if(documents.length &gt; 3) {
                      documents.splice(4, 0, {questionPostId: 0})
                      documents.splice(5, 0, {questionPostId: 1})
                  }
                  setAllQuestions(documents)
                  setUsers(documents)
  
              }
  
          })
      if (searchValue.length &gt; 2) {
          canGetUpdatesFromFirestore.current = false;
          functions.searchForSearchVal(searchValue, &quot;Sexuality&quot;)
              .then((result) =&gt; {
                  setAllQuestions(result);
              })
      } else {
          canGetUpdatesFromFirestore.current = true
      }
  }, [searchValue])
  
  function setUsers(docs){
      let arrFinal = []
      let copyOfAllQuestions = &quot;&quot;
          for(let i = 0; i&lt; docs.length; i++) {
              console.log(&quot;HERE&quot;)
              if (docs[i].postedBy) {
                  docs[i].ref.get().then(userFire =&gt; {
                      copyOfAllQuestions = {
                          ...allQuestions,
                          ...{hasPremium: userFire.data().hasPremium}
                      }
                  })
                  arrFinal.push(copyOfAllQuestions)
              }
  
          }
      setAllQuestions(arrFinal)
  }
  </code></pre>
  <p>Let me share some of my current state and what I am trying to accomplish.
  I have a <strong></strong> that display <strong>allQuestions</strong>. Each question data has a <strong>ref</strong> to its user document in firestore. For each question I need to check if that user <strong>hasPremium</strong>. How should I go about doing that the correct way?
  The problem currently is that I can get the data from my <strong>Users</strong> collection through the <strong>ref</strong>, but I have to refresh my state in order for it all to show.
  Could someone help me get on the right path / think correctly on this one please?</p>