Interactive Star Rating Component
In modern web applications, user feedback is paramount. A ubiquitous way for users to express their satisfaction with products or services is through star ratings. This problem challenges you to build a robust, reusable, and accessible star rating component that accurately reflects user input and provides a smooth interactive experience.
Your primary task is to create a React component called StarRating that allows users to select a rating using a series of stars.
maxRating prop. Each star should visually represent its state (filled or empty).initialRating prop to pre-select a rating when it first renders. This rating should be reflected visually.readOnly prop. When true, the component should display the initialRating but not allow any user interaction (hover or click). The cursor should also reflect this non-interactive state.onChange prop (a function) that is called with the new rating value whenever a user successfully selects a rating.readOnly mode.StarRating component renders correctly with maxRating and initialRating props.readOnly is true, no interactive effects (hover, click) are possible, and the cursor is default.onChange callback is invoked with the correct rating value upon selection.role="slider", aria-valuenow, aria-valuemax, aria-label) are used for screen reader compatibility.Constraints
maxRating prop will be an integer between 1 and 10.initialRating prop will be an integer between 0 and maxRating.onChange callback.StarRating component is designed, its API (props), and its ability to be reused in different contexts.Loading editor...