Skip to content
  • Unlock Pro
  • Log in with GitHub
Solution
Submitted over 1 year ago

Interactive Rating Component - React & Tailwind

react, tailwind-css
Justin Levy•100
@justinsane
A solution to the Interactive rating component challenge
View live sitePreview (opens in new tab)View codeCode (opens in new tab)

Solution retrospective


What are you most proud of, and what would you do differently next time?

I'm most proud of how I dynamically created the rating buttons.

 {[...Array(5).keys()].map((_, index) => {
            const value = index + 1;
            const isSelected = rating === value;
            return (
               handleRating(value)}
              >
                
                
                  {value}
                
              
What challenges did you encounter, and how did you overcome them?

I had challenges with the semi-transparent rating circles. My solution was to use absolute positioning which I wasn't too familiar with. I also used this approach for the top star image.

Another challenge was changing the rating circle's background to white after a selection. I added a new react state to assist with this. I'm not sure if it was entirely necessary. There's probably a more efficient solution.

What specific areas of your project would you like help with?

Am I using React state correctly in this example?

function App() {
  const [rating, setRating] = useState(null);
  const [submitted, setSubmitted] = useState(false);

  const handleSubmit = (e) => {
    e.preventDefault();
    if (rating !== null) {
      setSubmitted(true);
    }
  };
function Rating({ setRating, handleSubmit, rating }) {
  const handleRating = (value) => {
    setRating(value);
  };
Code
Loading...

Please log in to post a comment

Log in with GitHub

Community feedback

No feedback yet. Be the first to give feedback on Justin Levy'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

Stay up to datewith new challenges, featured solutions, selected articles, and our latest news

Frontend Mentor

  • Unlock Pro
  • Contact us
  • FAQs
  • Become a partner
  • Use cases

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