Skip to content
Submitted about 1 year ago

Interactive Rating Component using React JS, TypeScript & Tailwind CSS

react, typescript, vite, tailwind-css
@ejaay-dev
A solution to the Interactive rating component challenge

Solution retrospective


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

Adding some conditional logic for the element current state, if it is clicked or not.

{
  ratings.map((rating, index) => {
    // Check if this rating is selected
    const isSelected = selectedRatingIndex === index

    // Set the background color based on selection
    const bgColor = isSelected
      ? "bg-custom-orange cursor-"
      : "bg-dark-gray hover:bg-custom-white"

    // Set the text color based on selection
    const textColor = isSelected
      ? "text-black"
      : "text-light-gray group-hover:text-black"

    // This will output after conditional logic statement
    return (
       {
          setSelectedRatingIndex(index)
          onSelectRating(rating)
        }}
      >
        {rating}
      
    )
  })
}
What challenges did you encounter, and how did you overcome them?

At first, I am not familiar how does TypeScript works. But I overcome it by watching several tutorials via Youtube.

Code
Loading...

Please log in to post a comment

Log in

Community feedback

No feedback yet. Be the first to give feedback on ejaay-dev’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