
Product
A New Overview in our Dashboard
We redesigned Socket's first logged-in page to display rich and insightful visualizations about your repositories protected against supply chain threats.
react-rater
Advanced tools
npm install react-rater
import Rater from 'react-rater'
import 'react-rater/lib/react-rater.css'
// ...
render() {
return (<Rater total={5} rating={2} />)
}
Note: If your react version is under 16.8.0 without hooks support, please keep using react-rater@5
<Rater total={} rating={} interactive={} onRate={} onRating={} />
All attributes are optional.
total
: Number, default 5rating
: Number, default 0interactive
: Boolean, default true
. Create a read-only rater by setting this attribute to false
.onRate
: function({ rating })
. Callback to retrieve rating value. Called after rated.onRating
: function({ rating })
. Callback to retrieve rating value. Called during rating (mouse moving between stars).onCancelRate
: function({ rating })
. Called when mouse moves out from rater.From version 5.0.0, callback is split into onRate
& onRating
& onCancelRate
. onRate
is called when mouse click, while onRating
is called when mouse moves between star components and onCancelRate
is called when mouse leaves rater. Usually you only need onRate
.
Set interactive={false}
to create a read-only rater.
In read-only mode, rating
could contain a fractional part like 3.6
. (Thanks to @devmtnaing)
onRate
& onRating
(rating
is passed with the React's SyntheticEvent)
{
rating: Number
...syntheticEvent
}
$react-rater-link: #ccc !default; // color of star not rated
$react-rater-hover: #666 !default; // color of star on hover
$react-rater-active: #000 !default; // color of star rated
<Rater />
will repeat its children until counts reach total
. https://github.com/NdYAG/react-rater/blob/master/src/index.js#L69
In this way you can define your own 'star' component (src/star.js).
<Rater total={5}>
<Heart />
</Rater>
and style it based on these props:
{
isActive: PropTypes.bool,
isActiveHalf: PropTypes.bool,
willBeActive: PropTypes.bool,
isDisabled: PropTypes.bool
}
Valentine's Day:
Abilu judge system for Douban Music:
BSD.
FAQs
A star rater in react.js
We found that react-rater demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Product
We redesigned Socket's first logged-in page to display rich and insightful visualizations about your repositories protected against supply chain threats.
Product
Automatically fix and test dependency updates with socket fix—a new CLI tool that turns CVE alerts into safe, automated upgrades.
Security News
CISA denies CVE funding issues amid backlash over a new CVE foundation formed by board members, raising concerns about transparency and program governance.