Interactive Rating Component

Solution retrospective
The rating buttons required double click to hightlight in orange, because useState resets focus whenever value changes, not sure how to make it work on single click.
Please log in to post a comment
Log in with GitHubCommunity feedback
- @AlexKMarshall
Hey there. The problem you have described is likely because you have defined your
Button
component inside the body of theRating
component. This is invalid React code, because the component definition will get re-created every timeRating
re-renders, causing all sorts of unexpected behavior.The quick fix is to move the definition of
Button
to the top level of the file.However, for full accessibility, this should be a
<form>
with<input type="radio">
inside it. Doing it that way will allow the browser to properly communicate that this is a form, and it has something inside it that you can only select one of. You can also get rid of theuseState
because the form will manage its own uncontrolled state.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