Skip to content
  • Unlock Pro
  • Log in with GitHub
Solution
Submitted over 2 years ago

REACT + VITE TO DO APP

react, vite
Shane Chaffe•900
@Chaffexd
A solution to the Todo app challenge
View live sitePreview (opens in new tab)View codeCode (opens in new tab)

Solution retrospective


This took me a few days and had a few challenges on the way.. I decided to render the components for mobile different to how you might normally do it. I would really appreciate feedback on this!

Code
Select a file

Please log in to post a comment

Log in with GitHub

Community feedback

  • Pavel B.•270
    @Jagholin
    Posted over 2 years ago

    Some of the things that I would do differently:

    • you don't really need Sun and Moon components. Since you are using vitejs, it supports importing image assets and you can just set the svg files either as src attribute for an <img> tag, or as background-image CSS property on a div.
    • I find it better to destructure props immediately in the function argument list. Like this:
    const Sun = ({onClick}) => {...}
    

    This way, it is immediately apparent what props a component expects to receive, and you dont need to read the rest of the function code to find it out. But this is just my preference :)

    • when you have dependent variables like incompleteCount in the ToDo component, you can use useMemo hook instead, and get rid of associated useEffect. Like so:
    const incompleteCount = useMemo(
        () => toDoList.filter(item => !item.complete).length, 
        [toDoList]);
    
    • newList.splice(index, 0, newList.splice(newList.indexOf(draggedItem), 1)[0]) is a bit hard to read. I would write it out:
    newList.splice(newList.indexOf(draggedItem), 1); 
    newList.splice(index, 0, draggedItem);
    
    • I wouldn't use *.classList.add / remove functions, because they do the same thing as className JSX attribute. When you have multiple ways of doing the same thing, prefer to use that which is more idiomatic to the libraries you use.

    • This is a terrible way of generating "unique" ids: Math.floor(Math.random() * 5000000). Just use natural numbers in order: 0, 1, 2, 3 etc.

    • About your original way of dealing with mobile/desktop layouts... I don't see the point in doing it like this. Not only are you duplicating your code, but your site actually breaks if you resize it (ToDo component is unmounted and all data is lost)

    PS and additional thing:

    • It is good that you use key prop where React requires you to, but it seems that you dont really understand what it supposed to do. key allows React to distinguish components in an array, giving them something to be identified by. index here is not a good key, since it is possible to rearrange todo elements. You already have task.id property, so use it instead.
    <div 
                    key={entry.id}
                    ...
    >
    
    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

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