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

Landing page using React

react, vite
thomasrichmond•10
@thomasrichmond
A solution to the Interactive rating component challenge
View live sitePreview (opens in new tab)View codeCode (opens in new tab)

Solution retrospective


  • Used a lot of stuff learnt from Bob Zirolls React course (mapping, state etc), also used a couple things I learnt from some Odin Project work I used to get my CSS skills sharp again.
  • Really annoyed about the button clicking, couldn't figure out how to have their state managed separately for each button to hold the colour change, if anyone has any way to do this / suggestions please do.
  • Any suggestions on best practice or how i can improve this let me know!
Code
Couldn’t fetch repository

Please log in to post a comment

Log in with GitHub

Community feedback

  • Matt•180
    @mslee017
    Posted over 2 years ago

    Hey there! If you want to give it a go without exact code I'll try and lay steps our here for the button with state, and feel free to look at my project if you get stuck. For the button with state, what I did was create a state value called currentActive and by default it should be set to null. You can then create a function that takes an argument and all that function is going to do is setCurrentActive to the number it clicks, like so: 1). Create a state that will essentially hold the current active element of the button groups. It should be initialized to null

    2). Create a function to handle this state on click, it will need an argument (eventually receives index of the array being Mapped over). Function should simply then be used to set the current value of the state created above

    3). On click function inside the elements you are returning/mapping over. Map should use TWO arguments in this case, the number itself and the index argument the callback gives. Your function that is setting the state inside here should then take the index as its argument

    4). Conditional styles! Inside the classes, use template literal to check if the index is equal to the state value. If it is, it should be orange. If not, the dark blue.

    Good luck!

  • vinu cyril•980
    @vinuman
    Posted over 2 years ago

    Hello,

    Select all the buttons grouped under the class 'selections'.

    Declare a variable for the current active button.

    Add an event listener on the selections and declare the target. If the target has 'Button', apply background color and color properties to the target.

    Before executing this, check if there already exists an active button. If so, remove the background color and color of the same.

    Finally make the current target active button.:

    Code:

    selection.addEventListener('click', function(e){

    const target = e.target;
    
    if(target.matches('Button')){
    
       if(activeButton){
        activeButton.style.backgroundColor = '';
        activeButton.style.color = '';
       }
    
        target.style.backgroundColor = '#979797';
        target.style.color = '#fff';
        activeButton = target;
    }
    

    })

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

Oops! 😬

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

Log in with GitHub