Closed devYuraKim closed 3 months ago
CSS
.disable-star { filter: grayscale(1); }
JS
import './star-rating.css'; import { useState } from 'react'; export default function StarRating() { const [cursor, setCursor] = useState(0); const [rating, setRating] = useState(0); function Star({ i }) { return ( <div onClick={() => { setRating(i + 1); }} onMouseOver={() => setCursor(i + 1)} onMouseLeave={() => setCursor(rating)} className={`rating-star ${cursor < i + 1 && 'disable-star'}`} > ⭐ </div> ); } return ( <div className="rating-stars-container"> {Array(5) .fill(5) .map((e, i) => ( <Star i={i} key={e + i} /> ))} </div> ); }
CSS
JS