Skip to content
  • Unlock Pro
  • Log in with GitHub
Solution
Submitted about 3 years ago

Interactive comment section with React and useState

react
Jan Wągrowski•190
@JanWu100
A solution to the Interactive comments section challenge
View live sitePreview (opens in new tab)View codeCode (opens in new tab)

Solution retrospective


This challenge defeated me :), I did as many interactions as I could but I obviously dont know react well enough to pull it off :). I will come back to this challenge when I will learn a bit more about state and hooks. I will appreciate any tips on how to fix deleteReply function so that it only removes deeply nested reply instead of overwriting whole "comments" part of my DUMMY_DATA. :) cheers

Code
Select a file

Please log in to post a comment

Log in with GitHub

Community feedback

  • Sean Red•635
    @seanred360
    Posted about 3 years ago

    I recommend you use object destructuring in ALL of your components, you have a lot of duplicate variable names and collisions. I was very hard for me to understand what was going on. Pretty easy fix though. Check my pull request on Github for details on how to do that. Good job so far, you seem to grasp Javascript pretty well. You just need to learn the best practices for React.

    Marked as helpful
  • Sean Red•635
    @seanred360
    Posted about 3 years ago

    You no not need to fix your handling of deleteReply. For this small project what you did is fine. If the goal was to create a massive scalable database like Facebook has you would normalize the data, which means you would make all your data 1 level deep. So you would have a collection called "comments", that is an array of comment objects with the id, content, author, and the unique IDs of all the replies, but not their content. You would have another collection called 'replies' that is an array of reply objects with author, content, and the unique ID of the comment that you are replying to. You would have a collection called "users" that only an array of user objects with a username, photo, date joined etc. The reason you have everything spread out is because it would not be possible for 1 user to download every post and user's data on the entire database of Facebook on load. You have to put everything in small separated collections so you can only grab what you need. So when you want to fetch your replies you look at the replies IDs array in your comment and fetch only the replies from the replies collection that have the ID contained in your comment.

    Marked as helpful

Join our Discord community

Join thousands of Frontend Mentor community members taking the challenges, sharing resources, helping each other, and chatting about all things front-end!

Join our Discord
Frontend Mentor logo

Stay up to datewith new challenges, featured solutions, selected articles, and our latest news

Frontend Mentor

  • Unlock Pro
  • Contact us
  • FAQs
  • Become a partner

Explore

  • Learning paths
  • Challenges
  • Solutions
  • Articles

Community

  • Discord
  • Guidelines

For companies

  • Hire developers
  • Train developers
© Frontend Mentor 2019 - 2025
  • Terms
  • Cookie Policy
  • Privacy Policy
  • License

Oops! 😬

You need to be logged in before you can do that.

Log in with GitHub

Oops! 😬

You need to be logged in before you can do that.

Log in with GitHub

How does the accessibility report work?

When a solution is submitted, we use axe-core to run an automated audit of your code.

This picks out common accessibility issues like not using semantic HTML and not having proper heading hierarchies, among others.

This automated audit is fairly surface level, so we encourage to you review the project and code in more detail with accessibility best practices in mind.

How does the CSS report work?

When a solution is submitted, we use stylelint to run an automated check on the CSS code.

We've added some of our own linting rules based on recommended best practices. These rules are prefixed with frontend-mentor/ which you'll see at the top of each issue in the report.

The report will audit all CSS, SCSS and Less files in your repository.

How does the HTML validation report work?

When a solution is submitted, we use html-validate to run an automated check on the HTML code.

The report picks out common HTML issues such as not using headings within section elements and incorrect nesting of elements, among others.

Note that the report can pick up “invalid” attributes, which some frameworks automatically add to the HTML. These attributes are crucial for how the frameworks function, although they’re technically not valid HTML. As such, some projects can show up with many HTML validation errors, which are benign and are a necessary part of the framework.

How does the JavaScript validation report work?

When a solution is submitted, we use eslint to run an automated check on the JavaScript code.

The report picks out common JavaScript issues such as not using semicolons and using var instead of let or const, among others.

The report will audit all JS and JSX files in your repository. We currently do not support Typescript or other frontend frameworks.

Oops! 😬

You need to be logged in before you can do that.

Log in with GitHub

Oops! 😬

You need to be logged in before you can do that.

Log in with GitHub