Add feature voting to a React app
One useEffect loads the script, mounts the board inside a ref and cleans up on unmount.
Free for one project and 100 votes. Paid plans start with a 14 day trial, no card.
The component
The component keeps a ref to an empty div, loads the embed script if the page does not have it yet, calls init and mounts a widget into the ref.
One effect loads the script, mounts the board and cleans up.
It returns a cleanup that destroys the widget, so leaving the page leaves nothing behind.
Start with the script loader. A module level variable holds one promise, so however many times the component renders, the script tag is added once. The function resolves at once when window.VoteFirst already exists, and otherwise creates a script element for https://app.votefirst.app/embed/votefirst.js and resolves on its load event.
Inside the component, useEffect depends on the project and the key. It sets a cancelled flag, waits for the loader, then calls window.VoteFirst.init with the project slug and the embed key and mounts window.VoteFirst.roadmap(ref.current). The cleanup sets cancelled to true and calls destroy on the handle if one was made. The component returns a bare div with the ref.
The same shape works for every widget. Swap roadmap for board, changelog, topFeatures, features, voteButton or badge, and only the method name and the options object change. VoteFirst.report({ trigger: '#bug', board: 'bugs' }) sends bug reports to a board of their own.
import { useEffect, useRef } from 'react';
let loading;
function loadScript(src) {
if (window.VoteFirst) return Promise.resolve();
loading = loading || new Promise((resolve, reject) => {
const script = document.createElement('script');
script.src = src;
script.onload = resolve;
script.onerror = reject;
document.head.appendChild(script);
});
return loading;
}
export default function VoteFirstRoadmap({ project, embedKey }) {
const ref = useRef(null);
useEffect(() => {
let handle;
let cancelled = false;
loadScript('https://app.votefirst.app/embed/votefirst.js').then(() => {
if (cancelled) return;
window.VoteFirst.init({ project, key: embedKey });
handle = window.VoteFirst.roadmap(ref.current);
});
return () => {
cancelled = true;
if (handle) handle.destroy();
};
}, [project, embedKey]);
return <div ref={ref} />;
}Strict Mode
In development React mounts, unmounts and mounts again. Without a guard that is two script tags or two boards.
Strict Mode runs the effect twice. The component expects it.
The cancelled flag stops the first run from drawing, and the shared promise stops the second run from adding another script.
The failure shows up as a board that appears twice, or two script tags in the document head. The cause is a cleanup function that is missing, or a script appended from inside the effect on every run. Fixing it needs no library, only the two guards in the component above.
A host that wants to know when the SDK is ready can listen for the votefirst:ready event on document. It can also push a function onto window.vfq before the script loads, and that function is called once the script is up.
If the component sits in a shared layout and never unmounts across routes, nothing needs doing: the board stays where it is. If it unmounts when the route changes, cleanup removes it and the next mount draws a fresh one.
Fix the origin_not_allowed error
The embed key can be limited to the origins that may use it. A browser on any other origin gets a 403 and the code origin_not_allowed.
An origin includes the port, so http://localhost:3000 and http://localhost:5173 are two entries.
Under Share and Embed in the dashboard, list one origin per line. A bare host such as example.com is read as https. A wildcard such as https://*.example.com covers subdomains but not the bare domain, so add both when you want both. A single asterisk means every origin, and so does an empty list.
The allowlist keeps your key from working on somebody else's site. It does not make the key a secret, because a request from a terminal can send whatever origin it likes. That is acceptable, since the key opens only what your public board already shows. It is not an API key, and an API key must never appear in React code.
Rotating the key stops every page that still carries the old one, so do it only when the key has ended up somewhere it should not be. Votes and comments already recorded stay.
A button instead
VoteFirst.suggest({ trigger: '#feedback' }) opens the suggestion form over your page when that element is clicked.
Prefer a button to a whole board? Use the popup.
VoteFirst.report does the same for bug reports, and both take only options because there is nothing to render until they open.
Inside React, call the popup from the same effect and keep the handle. The cleanup calls destroy, which unbinds the trigger as well as closing the dialog. Skipping that call is the usual reason for one press opening two dialogs after a route change.
The form holds focus while it is open, closes on Escape and returns focus to the element that opened it. A visitor writes a heading of up to 254 characters and a reason of up to 2000. The widget stores the visitor's identity in local storage, not in a cookie.
Suggestions wait for your approval, as on the hosted board, and the dialog says so in plain words when it closes.
Server rendering
The component reads window and document only inside useEffect, which never runs on the server.
Server rendering is safe because the effect never runs there.
That is why a build step in Next.js passes without a window is not defined error.
In the App Router, mark the file with 'use client' and import the component into a server component as usual. Pass the project slug and the embed key as props from an environment variable. Both are public by design, so a NEXT_PUBLIC_ variable is the right place.
The widget renders after hydration, so the first paint shows an empty div and the board fills in a moment later. If layout shift matters, give the container a minimum height. The script is 87 KB uncompressed, and the stylesheet is optional: leave it out and the widgets arrive with no styling, which suits a team that writes every rule itself.
Styling hooks are plain vf- class names and data attributes such as data-status and data-feature-id, so your own CSS can reach them without a build step. The appearance option can also override individual color tokens, and setting it to false leaves every token to your stylesheet.
Your own interface
The widgets cover a board, a roadmap, a changelog and a vote button. A fully custom screen reads from the v3 API with the same embed key.
When the widget is not enough, call the API.
Reading a board and casting a vote work with the public key. Anything administrative needs a secret key on a server.
A custom interface is a few more files, not a new product. Fetch the features list for your project, draw each row yourself and send the vote to the vote route. The voter is minted for the browser on the first write, so there is no sign in to build.
API access with a secret key is on Free and Pro, and Lite does not have it. The public embed key and every widget work on every plan. That split decides the choice for most teams: stay with widgets unless the design truly cannot be bent with CSS.
What the component gives your app
A board with no build step of its own
The script is loaded on demand, so your bundle does not grow and there is no package to keep current.
Safe under Strict Mode
One promise and one cancel flag keep the script and the board from doubling in development.
Votes without sign in
Visitors vote with no account, and you can require sign in later through your own customers' tokens.
From empty component to a live board
Allow about fifteen minutes, including the key.
Copy the key and slug
Open Share and Embed in the dashboard and copy both values.
Add your dev origin
List http://localhost:3000 or your own port so the browser is allowed.
Paste the component
Create the file, pass the two props and render it where the board belongs.
Cast a vote
Vote from the page and look for the count in your dashboard.
What to know before you ship
- The widget draws after the page loads, so the first paint shows an empty container.
- The allowlist keeps a key off other sites but does not hide it.
- API routes with a secret key need Free or Pro, and that key stays on a server.
- An anonymous voter is a browser, so one person on two browsers can vote twice.
What React developers ask
Is there an npm package?
No. The integration is the script, loaded on demand by the component above. There is nothing to install and nothing to update.
Can the key be public in my repository?
Yes. The embed key is public by design and opens only what your public board already shows. Never commit an API key.
Does it work with Vite and Create React App?
Yes. The component only needs a browser. Add your dev server origin to the allowlist.
Can the board match my design?
Yes. Leave out the stylesheet and write your own rules for the vf- classes, or override color tokens with the appearance option.
Do visitors need to sign in?
No. Each browser gets an anonymous voter. Signing in through your own accounts is optional.
What does it cost?
Free holds one project and 100 votes. Lite is $9/mo, Pro is $39/mo, and both paid plans start with a 14 day trial and no card.
More ways to add a board
Widgets, buttons and the vote itself.
The roadmap embed
Show columns of requests on your own page.
The vote button
One button that casts a vote from any page.
The API
Routes for a fully custom interface.
Voting for an app you built by prompting
One script line and one prompt give it a roadmap.
Draw your own voting interface
Read, vote and comment from your own page.
Tools with a REST API
Six tools compared: which plan gives you the key.
The React docs page
A component that loads the script once and cleans up.
Mount the first board today
Free starts at one project and 100 votes. Move up to Lite at $9/mo or Pro at $39/mo whenever you outgrow it, with a 14 day trial and no card.