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

React and scss

Filip•350
@filip65
A solution to the Rock, Paper, Scissors game challenge
View live sitePreview (opens in new tab)View codeCode (opens in new tab)

Solution retrospective


It was fun to build this game. I tought that it will take me more time to build, but I've done it in two days so i'm happy! 😁 Made my best to make it as good as possible. I also made it as PWA and it was my first time doing that. Any feedback would be hightly appreceated! ❤

Code
Select a file

Please log in to post a comment

Log in with GitHub

Community feedback

  • Anton•515
    @antarya
    Posted about 4 years ago

    Hi Filip,

    It is really good, and the animation is nicely done 👍

    I would suggest a couple of refactoring/improvements that might clean the code a little bit and will point to the topic that might save you a day of debugging on another project.

    Good to know:

    • In your code you have setScore(score + 1); which should work as expected in this case but it is a safer way to do it using functional updates setScore((prevScore) => prevScore + 1). In this case, you can remove score from props, and make it safer for async cases, which is very well explained in this article https://kentcdodds.com/blog/use-state-lazy-initialization-and-function-updates#dispatch-function-updates. Resource regarding functional updates https://reactjs.org/docs/hooks-reference.html#functional-updates.

    • You might also consider useful this post that compares custom prop ref and ref using forwardRef https://stackoverflow.com/questions/58578570/value-of-using-react-forwardref-vs-custom-ref-prop.

    Refactoring/improvements:

    • In Choosing component you pass setIsChoosing which is used with handleUserChoice, why not to move setIsChoosing(false) to handleUserChoice?

    • In the Choosing component, if you update according to the previous suggestion, there is no need to have handleClick; you can directly pass handleUserChoice to Button.

    • Three-button in Choosing component looks like a good candidate to generate them on the fly:

      const icons = { 
        paper: iconPaper,
        scissors: iconScissors,
        rock: iconRock,
      };
      const choices = ['paper', 'scissors', 'rock'];
    
      function Choosing ... {
        ...
        choices.map((choice) =>
          <Button
            image={icons[choice]}
            type={choice}
            handleClick={handleUserChoice}
            text={`${choice} button`}
          />
        )
        ...
      }
    
    • The icons list can be reused in the Result component, which will make your code cleaner.
      // instead of this
      image={
        houseChoise === "paper"
          ? iconPaper
          : houseChoise === "rock"
          ? iconRock
          : iconScissors
      }
      // you can now write this
      image={icons[houseChoise]}
    
    • For accessibility, add alt on the Rules close button.

    • Try to stick to one className format (score__text, house-btn, playAgainBtn) and do not use id for styling. Check this formatting rules http://getbem.com/introduction/.

    • I also noticed that when height is small, elements are on top of each other.

    It is awesome that you added PWA support 🚀

    I hope this will be helpful.

    See you on the coding trail.

    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