Star Rating

Yangshun TayEx-Meta Staff Engineer
语言

Create a star rating widget that allows users to select a rating value.

Requirements

  • The widget accepts three parameters: the maximum number of stars, the number of currently filled stars, and a callback fired with the new value whenever the rating changes.
  • When a star is clicked, it is filled along with all the stars to its left, and the change callback is fired with the new rating.
  • Hovering over a star fills that star and all stars to its left.
    • The stars that need to be filled during hover take priority over the existing filled state.
    • If the cursor leaves the widget and no new selection is made, the appropriate stars revert to the filled state before hovering.
  • Make the star rating widget reusable such that multiple instances can be rendered within the same page.

The star icons, both empty and filled, are provided as SVGs.

A StarRating.js skeleton component has been created for you. You are free to decide the props of <StarRating />.

在这些公司提问

高级功能购买高级版以查看出题公司。
查看计划

加载编辑器

    Star Rating 在 React | UI 面试问题