react-canvas-confetti provides a React-friendly interface for the popular canvas-confetti library, enabling developers to easily integrate various confetti, fireworks, and particle animations into their applications. As of version 2.0.7, it offers two primary usage patterns: a simplified preset system (e.g., `Fireworks`) for common animation templates with customizable settings, and a lower-level API that grants direct access to the `canvas-confetti` instance for creating bespoke animation algorithms. The library ships with TypeScript types, promoting robust development. While no explicit release cadence is documented, its active GitHub repository and npm download statistics suggest consistent maintenance and updates, typically aligning with the underlying `canvas-confetti` library's evolution and React ecosystem best practices. It differentiates itself by abstracting away direct DOM manipulation for canvas elements, providing a declarative component-based approach.
npm install react-canvas-confettiVerified import paths — ran on the pinned version, not inferred.
This quickstart demonstrates how to integrate the `Fireworks` preset component and manually control its animation using the `ConductorInstance` obtained from the `onInit` callback. It showcases single bursts and continuous firing patterns.
Ensure `react` and `react-dom` are installed: `npm install react react-dom`.
Avoid direct DOM manipulation of the canvas element if `useWorker` is enabled. Control confetti animations exclusively through the component's props or the `canvas-confetti` instance's API.
Pass `width` and `height` props to the component or ensure the canvas container has defined dimensions. E.g., `<Fireworks width={window.innerWidth} height={window.innerHeight} />`.Verify the exact import path for the preset you are trying to use. Presets are typically located under `dist/presets/`.
If using CommonJS, ensure you're importing `ReactCanvasConfetti` correctly. If using ESM, make sure to use `import ReactCanvasConfetti from 'react-canvas-confetti';` for the default export.
Add `import React from 'react';` at the top of your component file, especially if using older React versions or specific build configurations. For newer React (17+ with new JSX transform), this is often not required, but can still be a symptom of a misconfigured build or missing peer dependency.