We take the data from our useQuery
result and display it in an unordered list element.
We need to make sure to return a loading indicator when result.data
is undefined. When result.data
is truthy, we know that the GraphQL request has returned the data we asked for.
Instructor: [0:00] Now that we're getting comments, let's render them to the page. Down in our comments component, let's remove this console.log. Instead of returning null, we'll return an unordered list. We will go result.data, then GitHub.repository.issue comments.nodes. We know nodes is an array.
[0:37] We can map for each comment node. We will return an li with comment node.body, type error, "You cannot read property GitHub of undefined." We're getting this error because on our first render, we're trying to access data that useQuery hasn't returned anything yet, so we need to check against this.
[1:15] If not result.data return loading. Now we get loading. There's all of our comments. Looks like we forgot a key, which is important for React rendering. I add key = {comment.node.id}.
Member comments are a way for members to communicate, interact, and ask questions about a lesson.
The instructor or someone from the community might respond to your question Here are a few basic guidelines to commenting on egghead.io
Be on-Topic
Comments are for discussing a lesson. If you're having a general issue with the website functionality, please contact us at support@egghead.io.
Avoid meta-discussion
Code Problems?
Should be accompanied by code! Codesandbox or Stackblitz provide a way to share code and discuss it in context
Details and Context
Vague question? Vague answer. Any details and context you can provide will lure more interesting answers!