react-confetti is a React component designed to easily add customizable confetti effects to web applications. It provides a declarative way to render a shower of confetti, suitable for celebrations, achievements, or any event requiring a festive visual flourish. The current stable version is 6.4.0, with the project demonstrating an active release cadence, including multiple updates in early 2025 to add features, fix bugs, and ensure compatibility with newer React versions. Key differentiators include its simplicity as a React component, comprehensive TypeScript type definitions, and highly configurable properties such as `width`, `height`, `numberOfPieces`, and `confettiSource`. It's built to run efficiently in the browser, focusing solely on the visual confetti effect without external dependencies for physics or animation beyond what React and the browser provide, making it lightweight and easy to integrate.
npm install react-confettiVerified import paths — ran on the pinned version, not inferred.
This quickstart demonstrates how to integrate `react-confetti` into a React application, dynamically adjusting to window size changes using a custom hook, and configuring various confetti properties. It also includes an example of programmatically stopping the confetti after a duration and a toggle button.
Upgrade your Node.js environment to version 10.18 or higher to meet the minimum requirement. For optimal performance and security, consider using the latest LTS version of Node.js.
Always provide `width` and `height` props, typically by using a `useWindowSize` hook (as shown in the quickstart) or by manually tracking and passing the current dimensions of the canvas's container.
Ensure your project's React version is compatible with the specified peer dependency range. Upgrade or downgrade React as necessary, or install an older version of `react-confetti` that supports your React version.
For smooth transitions when parameters change, utilize the `tweenFrom` property available since v6.4.0. For older versions, managing the state of `numberOfPieces` or `confettiSource` more carefully to prevent jarring changes is required.
Conditionally render the `Confetti` component only on the client-side, for example, by using `typeof window !== 'undefined'` checks or dynamic imports with `next/dynamic` or similar mechanisms.
Ensure your build tooling (Webpack, Rollup, etc.) is correctly configured to handle both ESM and CommonJS modules. Upgrading `react-confetti` to version 6.2.2 or newer, which includes fixes for building multiple module types, often resolves these issues.
Implement a mechanism (such as a custom `useWindowSize` hook or `ResizeObserver`) to track and pass the current `width` and `height` of the intended confetti area to the `Confetti` component props.