Hi, it seems I’m not the only one who struggled a lot with this project, so I figured I’d share my working solution for anyone who needs one to compare to. I added some comments in the code but mostly just for the parts I struggled with, so feel free to ask questions
Some general notes:
- Not every article has comments. This includes the first one, which ofc is the one you’re likely to check. Check the article about Kamala Harris, which should have two comments by default.
- The component is not re-rendered when you submit a comment, which seems to be intended as far as I can tell? So you have to click a different article and then click back to see the comment you posted.
- I used the browser console for all my console logging etc. I just put the console.logs in places where they would trigger when the components rendered or something similar, since there seems to be no way to run the code and have the console in the editor actually show the logs.
THIS hint especially had me confused for days
if (!comments) {
return null;
}
return (
<ul>
{
comments.map(comment => {
// Return a Comment component
}
}
</ul>
)
But I’ve added a comment in CommentList.js explaining how I got around it: