
Company News
Socket Named Top Sales Organization by RepVue
Socket won two 2026 Reppy Awards from RepVue, ranking in the top 5% of all sales orgs. AE Alexandra Lister shares what it's like to grow a sales career here.
react-vote
Advanced tools
React component for simple voting system, easy to customize and internationalize
React component for simple voting system, easy to customize and internationalize
npm install react-vote --save
All options such as multiple, expansion, downvote, autoClose, showTotal, etc. are now available in the data object. You can now control the whole vote system with one data object. Thus, multiple, expansion, total, downvote, autoClose props are omitted.
For a new voting system, Do NOT put the data prop.
Put onCreate, onEdit, onUpvote, onDownvote, onClose, onReset, onExpand callback functions to get voting data and connect with database.
Use unique identifier of client IP address as clientId to check whether the client already voted or not.
You can only create, edit, reset or close vote when isAdmin prop is true. Make it false when you open vote to others.
var ReactVote = require('react-vote'); // or import ReactVote from 'react-vote';
<ReactVote
styles={customStyle}
text={customText}
onCreate={onCreate}
onUpvote={onUpvote}
onClose={onClose}
onReset={onReset}
isAdmin={true}
clientId={clientId}
/>
You can get voting data as a parameter inside the callback function. See Props section below for more information.
function onCreate (data, diff) {
// Save data into the databasehere!
console.log(data); // { title: 'title of this vote', items: [{ title: 'option1', count: 5, voters: ['a', 'b', 'c', 'd', 'e'] }, { title: 'option2', count: 3, voters: ['f', 'g', 'h'] }], closed: false, multiple: false, expansion: false, voters: ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h'] }
}
For ongoing vote or voting result, fetch vote data from the database and put it into the data prop. This component will read the data prop and execute it. The structure of data prop is detailed below.
<ReactVote
data={data} // put data object here and you will get ongoing vote
onUpvote={onUpvote}
isAdmin={false}
clientId={clientId}
styles={customStyle}
text={customText}
errorMessage={customMessage}
/>
I didn't put any css codes for your customization. You can use styles prop to style it in your own way. styles prop is detailed in below. Also, you can change texts by using text prop.

Tell react-vote whether the client is an admin or not. Only admins can close and reset vote.
Put unique identifier of client here. React-vote will check whether that client already voted or not. Good example of identifiers are IPs or ObjectIds
Object that contains the whole information about the vote
{
title: String, // Title of vote
items: [ // Array of vote options
{
title: String, // Title of option
count: Number, // Number of votes
total: Number, // Number of total votes(including downvote)
reason: Boolean, // Need to put reason why voted
reasons: [String], // Array of reasons why voted
voters: [String/Number] // Array of unique identifers of all voters for this option
downvoters: [String/Number] // only downvoters
upvoters: [String/Number] // only upvoters
adder: String/Number // Unique identifier of the one who added this item(for expandable vote)
}
],
closed: Boolean, // Whether this vote is closed or not. If this prop is true, you can only see the result, otherwise you can toggle between voting view and result view.
voters: [String/Number] // Array of unique identifiers of all voters.
autoClose: Number // Number which closes vote when reached
multiple: Boolean // Whether voters can choose multiple options
expansion: Boolean // Whether voters can add new option
downvote: Boolean // Whether to allow downvote
showTotal: Boolean // Whether to show total votes in result view
creator: String/Number // Unique identifier of the one who create this vote.
}
It's an callback function triggered when you create a new vote. The only parameter is a whole vote data.
It's an callback function triggered when you edit an existing vote. The only parameter is a whole vote data(edited)
It's an callback function triggered when you upvote. The first parameter is a whole vote data, the second is the difference between previous and current data.
// diff object
{
index: Number,
item: Object,
voter: String/Number
}
It's an callback function triggered when you downvote. The first parameter is a whole vote data, the second is the difference between previous and current data.
It's an callback function triggered when the vote is closed. The only parameter is a whole vote data.
It's an callback function triggered when the vote is reset. The only parameter is a whole vote data.
It's an callback function triggered when you add a new option. The first parameter is a whole vote data, the second is the added item.
A group of classNames in this voting component. You can change these for style customization by mapping classNames with css files.
A group of texts in this voting component. You can change these for i18n(internationalization).
Messages of error, triggered when you try something invalid.
Please contribute to this package via Pull Request, or you can open Issues!
MIT
FAQs
React component for simple voting system, easy to customize and internationalize
The npm package react-vote receives a total of 113 weekly downloads. As such, react-vote popularity was classified as not popular.
We found that react-vote 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.

Company News
Socket won two 2026 Reppy Awards from RepVue, ranking in the top 5% of all sales orgs. AE Alexandra Lister shares what it's like to grow a sales career here.

Security News
NIST will stop enriching most CVEs under a new risk-based model, narrowing the NVD's scope as vulnerability submissions continue to surge.

Company News
/Security News
Socket is an initial recipient of OpenAI's Cybersecurity Grant Program, which commits $10M in API credits to defenders securing open source software.