import React from 'react'; const StarRating = ({ rating }) => { const normalizedRating = Math.min(Math.max(0, rating), 5); const filledStars = Math.floor(normalizedRating); const hasHalfStar = normalizedRating - filledStars >= 0.5; return (
{[...Array(filledStars)].map((_, index) => ( ))} {hasHalfStar && } {[...Array(5 - filledStars - (hasHalfStar ? 1 : 0))].map((_, index) => ( ))}
); }; export default StarRating;