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

Comment section ✨PLUS✨

react, redux-toolkit, styled-components, typescript
turtlecrab•550
@turtlecrab
A solution to the Interactive comments section challenge
View live sitePreview (opens in new tab)View codeCode (opens in new tab)

Solution retrospective


I changed expected behaviour to make the challenge more interesting:

  • You can reply to any comment at any depth (so it's a comment tree like on facebook)
  • You can change the current user (via the button in the top-right)
  • No sorting of first-level comments (it's easily done but boring and kinda useless here)

Also:

  • Ctrl+Enter in the textarea submits the form
  • You cannot add empty comments
  • You cannot vote on your own comments
  • A user can vote only +1 or -1 (no multiple votes)
  • You can cancel your vote by voting the opposite
  • Your vote is shown
  • Cancel button is shown when updating the comment

Very interesting project, took a lot of time though. At first I implemented the majority of functionality using props-drilling 😈. Then moved the state to a context 🤷‍♂️. Then rewrote everything with redux 💪

  • Used redux-thunk's synchronous action-function to move comment creation non-pure logic(time and random id) out of components
  • Used timeago.js to format the time
  • react-remove-scroll-bar and TrapFocus from @mui/base for the delete modal
  • Drawer from @mui/material for the users drawer
  • React.memo with redux docs best practices to minimize rerenders

❔ Questions:

  • Are there best practices for writing synchronous thunk actions? Redux docs don't tell where to put them. I'm pretty sure slices are the place for them(since normal action-creators are exported from the slices and components don't need to know what kind of action they import), but I'd love to confirm and see them in action(pun intended) in the real projects.
  • Did I do well with minimizing rerenders? I think I did, but would love to get feedback on this.
  • The Comment component looks pretty intimidating. I thought about moving some stuff from it to separate components, but to me nothing makes sense to extract. What do you think? Also there are so many handler functions, maybe I should've implemented it differently?

Feedback is appreciated!

Code
Couldn’t fetch repository

Please log in to post a comment

Log in with GitHub

Community feedback

No feedback yet. Be the first to give feedback on turtlecrab's solution.

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.