import React, {useState} from 'react'; const STARS = [1, 2, 3, 4, 5]; const WORDS = {1: 'Poor', 5: 'Great'}; // A rating out of five as stars. They are real radio buttons underneath, so // the arrow keys and screen readers work as they do for any radio group; the // stars just light up as far as the one hovered, or chosen. `value` is a number // from 1 to 5, or null for no rating, and Clear puts it back to that. export default function StarRating({id, label, value, onChange}) { const [hovered, setHovered] = useState(null); const lit = hovered ?? value ?? 0; return (
{label}
setHovered(null)}> {STARS.map((number) => ( onChange(number)} />