Add Snaglist to a React, Vue, Svelte or other framework app
How-to
In an app built with a framework, load snaglist.js as a plain file and start it once, when the app first
loads. Snaglist keeps its own element outside your components, so your framework never redraws it.
Before you begin
- Download
snaglist.js, as in step 1 of Add Snaglist to a website.
Steps
- Put
snaglist.jsin the folder your framework copies as it is, usuallypublic/(React with Vite, Vue, Next.js, Astro) orstatic/(SvelteKit). - Load it in the page's HTML shell (
index.html, or your root layout), before the closing</body>:
<script src="/snaglist.js" defer></script>
- Start it once, in the code that runs when the app loads, not inside a component that can appear twice.
In React, for example, in
main.jsxafter the app is mounted:
window.addEventListener("load", () => {
window.Snaglist?.start({
app: "My app",
version: import.meta.env.VITE_APP_VERSION,
enabled: import.meta.env.MODE !== "production",
send: { github: { repo: "owner/repo" } },
});
});
- Run your app and check that Send feedback appears.
Things to note
- Snaglist reads the address each time someone reports, so page changes inside a single-page app are picked up without anything extra.
- With TypeScript, add
declare global { interface Window { Snaglist?: any } }to a types file. - To name components clearly in reports, read Name the parts of your pages.