title: Trying to call a document id from a sub-collection in firestore
body: <p>I'm trying to run a delete function that should be fairly straight forward but i'm not getting it.</p>
  <p>I referenced the document within the sub-collection but it doesn't seemed to be referenced correctly. When I hard code the answer documents id it performs the function but when I try to reference it doesn't work.</p>
  <p>I have the document information stored in an array but I need to cycle through the array to find the id that matches the post. I'm having trouble grabbing the reference from 'getAnswer' once it is stored.</p>
  <p>Here is the code:</p>
  <pre><code>    const [getAnswer, setGetAnswer] = useState([]);
  
      useEffect(() =&gt; {
      let mounted = true;
  
      db.collection(&quot;questions&quot;)
        .doc(questionId)
        .collection(&quot;answer&quot;)
        .orderBy(&quot;timestamp&quot;, &quot;desc&quot;)
        .onSnapshot((snapshot) =&gt; {
          if (mounted) {
            setGetAnswer(
              snapshot.docs.map((doc) =&gt; ({
                id: doc.id,
                answers: doc.data(),
              }))
            );
          }
        });
  
      return () =&gt; (mounted = false);
    }, []);
  
    const handleDeletePost = (e) =&gt; {
      if (user) {
        db.collection(&quot;questions&quot;)
          .doc(questionId)
          .collection(&quot;answer&quot;)
          .doc(getAnswer.id)
          .delete();
      }
    };
  
    const answerMenuId = &quot;primary-answer-account-menu&quot;;
    const answerRenderMenu = (
      &lt;Menu
        anchorEl={anchorEl}
        anchorOrigin={{ vertical: &quot;top&quot;, horizontal: &quot;right&quot; }}
        id={answerMenuId}
        keepMounted
        transformOrigin={{ vertical: &quot;top&quot;, horizontal: &quot;right&quot; }}
        open={isMenuOpen}
        onClose={handleMenuClose}
      &gt;
        &lt;MenuItem onClick={handleMenuClose}&gt;Edit&lt;/MenuItem&gt;
        &lt;MenuItem onClick={handleMenuClose} onClick={handleDeletePost}&gt;
          Delete
        &lt;/MenuItem&gt;
      &lt;/Menu&gt;
    );
  </code></pre>
  <p>For a bit more context I would like to delete an answer document based on the id of the document. Here is a screenshot of the database:</p>
  <p><a href="https://i.stack.imgur.com/PMamR.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/PMamR.png" alt="enter image description here" /></a></p>