These React components can render rating symbols, but fractional display, selectable increments and value control are separate contracts. Compare the input behavior and integration requirements rather than assuming a partial star display means partial-star selection.
A review average may need a partially filled symbol while a voting control needs defined selectable steps, focus and change behavior. Decide which role is required before choosing a component. Rendering a decimal average and accepting a decimal vote are different capabilities.
@smastrom/react-rating uses a value/onChange model and customizable SVG styles. Its published setup imports a stylesheet and requires React and React DOM 18 or later. Follow its interaction and read-only configuration rather than assuming a decorative output and an input share every event behavior.
react-rating exposes start, stop and step values for its scale and a fractions setting for subdivisions. Its initialRating and onChange contract, custom empty/full symbols and placeholder behavior differ from the first package. The number of symbols and the numeric range are not always the same thing.
react-star-ratings displays fractional aggregate values using SVG fill. In the published implementation, its change callback selects whole star indices; providing a decimal rating prop does not add fractional pointer selection. It also declares React 16 as a direct dependency rather than a broad current React peer, which matters in an application using a different React installation.
Check labels, keyboard operation, read-only behavior and the application's state updates for the selected component. A property named disabled or readonly and an advertised accessibility goal do not prove that every assembled use has been tested. Imports and callback names differ across these packages, so migration must adapt the state and rendering model.
Use the controlled SVG approach when it matches the design system, the configurable scale/symbol approach when those semantics are required, or the aggregate-display component when its current dependency and input contracts fit. Keep display precision and input precision explicit, and validate the actual interface rather than ranking the packages by generic customization claims.
Choose it for configurable symbols and a rating scale defined through start, stop, step and fractions. Its initialRating/onChange interface differs from a value-controlled component, so coordinate application updates with that API.
Choose it for its controlled rating and SVG styling approach in a React 18-or-later application. Import its stylesheet and check interactive versus read-only configuration against the desired input behavior.
Choose it when its SVG aggregate display and whole-star click contract match an existing integration. The current package directly depends on React 16, and fractional visual fill is not a fractional-click input contract.
React Rating is a react rating component which supports custom symbols both with inline styles and glyphicons found in popular CSS Toolkits like Fontawesome or Bootstrap.
This React component was inspired by the jQuery plugin bootstrap-rating.
See react-rating in action.
You can install react-rating component using the npm package manager:
npm install --save react-rating
The react-rating component peer depends on the React library.
You can install React using npm too:
npm install --save react
If you are using a version of React Rating < v1.0 be aware that there are API changes between anything < v1.0 and v1.0 . See the Properties and Deprecated Properties and Callbacks sections below for a documentation of the current API and how it compares to the old.
Require the Rating Component
var Rating = require('react-rating');
Start using it
With raw javascript:
React.createElement(Rating)
Or with JSX:
<Rating />
| Property | Type | Default | Description |
|---|---|---|---|
start | number | 0 | Range starting value (exclusive). |
stop | number | 5 | Range stop value (inclusive). |
step | number | 1 | Describes how many values each Symbol represents. For example, for a start value of 0, a stop value of 10 and a step of 2, we will end up with 5 Symbols, with each Symbol representing value increments of 2. |
fractions | number | 1 | Number of equal subdivisions that can be selected as a rating in each Symbol. For example, for a fractions value of 2, you will be able to select a rating with a precision of down to half a Symbol. Must be >= 1 |
initialRating | number | 0 | The value that will be used as an initial rating. This is the old initialRate. |
placeholderRating | number | 0 | If you do not define an initialRating value, you can use a placeholder rating. Visually, this will have the same result as if you had defined an initialRating value. If initialRating is set placeholderRating is not taken into account. This is the old placeholderRate |
readonly | bool | false | Whether the rating can be modified or not. |
quiet | bool | false | Whether to animate rate hovering or not. |
direction | ltr or rtl | ltr | The direction of the rating element contents |
emptySymbol | element or object or string or array | Style.empty | React element, inline style object, or classes applied to the rating symbols when empty. Can also be an array of such symbols that will be applied in a circular manner (round-robin). This is the old empty. |
fullSymbol | element or object or string or array | Style.full | React element, inline style object, or classes applied to the rating symbols when full. Can also be an array of such symbols that will be applied in a circular manner (round-robin). This is the old full. |
placeholderSymbol | element or object or string or array | Style.placeholder | React element, inline style object, or classes applied to the placeholder rating symbols. Can also be an array of such symbols that will be applied in a circular manner (round-robin). This is the old placeholder. |
| Callback | Type | Description |
|---|---|---|
onChange | function (value) {} | Gets called with the value when a different value than the currently set is selected. |
onClick | function (value) {} | Gets called with the value when a symbol is clicked. The value is equal to the value that corresponds to that part of the symbol. |
onHover | function (value) {} | Gets called with the value when you hover over a symbol. The value is equal to the value that corresponds to that part of the symbol. Gets called in quiet mode too. When hover ends, gets called with no value (i.e. undefined as the value). |
This is a list of deprecated properties and callbacks from versions older than v1.0
onRateinitialRateplaceholderRateemptyfullplaceholder