react-confetti vs canvas-confetti vs dom-confetti vs confetti-js
JavaScript Confetti Libraries Comparison
1 Year
react-confetticanvas-confettidom-confetticonfetti-jsSimilar Packages:
What's JavaScript Confetti Libraries?

Confetti libraries are JavaScript packages designed to create celebratory animations that simulate the effect of confetti falling on the screen. These libraries are often used in web applications to enhance user experience during events like successful form submissions, achievements, or special occasions. They provide developers with easy-to-use functions to trigger confetti effects, adding a festive touch to user interactions without the need for complex animations or graphics.

Package Weekly Downloads Trend
Github Stars Ranking
Stat Detail
Package
Downloads
Stars
Size
Issues
Publish
License
react-confetti2,359,2131,577220 kB22 days agoMIT
canvas-confetti711,28111,08492.3 kB3510 months agoISC
dom-confetti70,51924313.1 kB13-MIT
confetti-js28,98860956.2 kB17-MIT
Feature Comparison: react-confetti vs canvas-confetti vs dom-confetti vs confetti-js

Rendering Method

  • react-confetti:

    react-confetti leverages React's rendering lifecycle to create confetti effects within React components. It integrates smoothly with React's state management, allowing for easy updates and re-renders based on component state.

  • canvas-confetti:

    canvas-confetti uses the HTML5 canvas element to render confetti, allowing for high-performance animations and detailed visual effects. This method is efficient for rendering large numbers of particles and can handle complex animations without significant performance drops.

  • dom-confetti:

    dom-confetti also utilizes DOM manipulation to create confetti effects, but it is designed to be lightweight and easy to implement. It focuses on adding confetti to specific elements, making it ideal for targeted animations without needing a full canvas setup.

  • confetti-js:

    confetti-js operates directly on DOM elements, creating confetti effects by manipulating the styles of existing elements. This approach is simpler and can be more intuitive for developers who are familiar with traditional DOM manipulation techniques.

Customization Options

  • react-confetti:

    react-confetti allows for customization through props, enabling developers to easily adjust particle colors, count, and duration directly within their React components. This makes it convenient for developers familiar with React's props system.

  • canvas-confetti:

    canvas-confetti offers extensive customization options for confetti particles, including colors, shapes, sizes, and gravity. Developers can fine-tune the appearance and behavior of the confetti to match the theme of their application, making it highly adaptable for various use cases.

  • dom-confetti:

    dom-confetti allows for straightforward customization of colors and particle styles, focusing on ease of use. It is designed for developers who want to quickly implement confetti effects with minimal configuration, making it user-friendly for quick projects.

  • confetti-js:

    confetti-js provides basic customization options such as colors and particle count, but it is less flexible than canvas-confetti. It allows developers to quickly set up confetti effects with some level of customization without overwhelming complexity.

Performance

  • react-confetti:

    react-confetti is efficient within the React ecosystem, but its performance is tied to React's rendering cycle. It works best for moderate use cases where the number of particles is manageable and can be optimized through React's lifecycle methods.

  • canvas-confetti:

    canvas-confetti is optimized for performance, especially when rendering a large number of particles. The use of the canvas element allows for smooth animations even on lower-end devices, making it suitable for applications that require high-performance graphics.

  • dom-confetti:

    dom-confetti is lightweight and performs well for basic animations, but its performance can be affected by the number of DOM manipulations. It is ideal for simple use cases where performance is not a critical concern.

  • confetti-js:

    confetti-js performs well for smaller animations but may struggle with performance if too many particles are rendered simultaneously. It is best suited for simple effects rather than complex animations that require extensive particle manipulation.

Ease of Use

  • react-confetti:

    react-confetti is user-friendly for React developers, as it integrates seamlessly into the React component model. Its API is intuitive for those familiar with React, making it easy to implement and customize.

  • canvas-confetti:

    canvas-confetti has a moderate learning curve due to its reliance on the canvas API. Developers need to understand how to work with canvas elements and manage animations effectively, but it offers great flexibility once mastered.

  • dom-confetti:

    dom-confetti is designed for simplicity and ease of use, allowing developers to add confetti effects with minimal code. It is particularly suitable for those who prefer straightforward implementations without extensive configuration.

  • confetti-js:

    confetti-js is easy to use and requires minimal setup. Developers can quickly implement confetti effects with simple function calls, making it accessible for beginners and those looking for quick solutions.

Integration

  • react-confetti:

    react-confetti is specifically built for React applications, providing a seamless integration experience. It allows developers to easily incorporate confetti effects into their React components, making it the best choice for React-based projects.

  • canvas-confetti:

    canvas-confetti can be integrated into various web applications, but it requires a good understanding of the canvas API. It is versatile and can be used in both vanilla JavaScript and frameworks like React or Vue with some additional setup.

  • dom-confetti:

    dom-confetti is designed for easy integration with existing DOM elements, making it ideal for projects that need to add confetti effects without extensive refactoring. It works well in any web environment.

  • confetti-js:

    confetti-js is straightforward to integrate into any web project, as it relies on standard DOM manipulation. It can be used in both simple HTML pages and more complex applications without much overhead.

How to Choose: react-confetti vs canvas-confetti vs dom-confetti vs confetti-js
  • react-confetti:

    Use react-confetti if you are building a React application and want a library specifically designed for React's component-based architecture. It provides an easy way to integrate confetti animations into React components, making it ideal for developers who prefer a declarative approach to UI updates.

  • canvas-confetti:

    Choose canvas-confetti if you need a lightweight library that utilizes the HTML5 canvas element for high-performance confetti animations. It's ideal for applications that require detailed customization of the confetti's appearance and behavior, such as colors, shapes, and gravity settings.

  • dom-confetti:

    Opt for dom-confetti if you are looking for a library that integrates seamlessly with existing DOM elements. It allows for easy customization and is perfect for developers who want to add confetti effects to specific parts of their web pages without extensive coding or setup.

  • confetti-js:

    Select confetti-js for a straightforward and flexible solution that works well with DOM elements. It is particularly useful for projects where you want to trigger confetti effects on specific elements without the overhead of canvas rendering. This package is great for quick implementations with minimal setup.

README for react-confetti

react-confetti

Confetti without the cleanup. Demo

Build Status npm npm bundle size npm type definitions

Based on a pen by @Gthibaud: https://codepen.io/Gthibaud/pen/ENzXbp

demogif

Install

npm install react-confetti

Use

width and height props are recommended. They will default to the initial window dimensions, but will not respond to resize events. It is recommended to provide the dimensions yourself. Here is an example using a hook:

import React from 'react'
import { useWindowSize } from 'react-use'
import Confetti from 'react-confetti'

export default () => {
  const { width, height } = useWindowSize()
  return (
    <Confetti
      width={width}
      height={height}
    />
  )
}

Props

| Property | Type | Default | Description | | ---------------- | --------------------- | --- | --- | | width | Number | window.innerWidth \|\| 300 | Width of the <canvas> element. | | height | Number | window.innerHeight \|\| 200 | Height of the <canvas> element. | | numberOfPieces | Number | 200 | Number of confetti pieces at one time. | | confettiSource | { x: Number, y: Number, w: Number, h: Number } | {x: 0, y: 0, w: canvas.width, h:0} | Rectangle where the confetti should spawn. Default is across the top. | | friction | Number | 0.99 | | | wind | Number | 0 | | | gravity | Number | 0.1 | | | initialVelocityX | Number \| { min: Number, max: Number } | 4 | Range of values between which confetti is emitted horizontally, positive numbers being rightward, and negative numbers being leftward. Giving a number x is equivalent to giving a range { min: -x, max: x }. | | initialVelocityY | Number \| { min: Number, max: Number } | 10 | Range of values between which confetti is emitted vertically, positive numbers being downward, and negative numbers being upward. Giving a number y is equivalent to giving a range { min: -y, max: 0 }.| | colors | String[] | ['#f44336'
'#e91e63'
'#9c27b0'
'#673ab7'
'#3f51b5'
'#2196f3'
'#03a9f4'
'#00bcd4'
'#009688'
'#4CAF50'
'#8BC34A'
'#CDDC39'
'#FFEB3B'
'#FFC107'
'#FF9800'
'#FF5722'
'#795548']
| All available Colors for the confetti pieces. | | opacity | Number | 1.0 | | | recycle | Bool | true | Keep spawning confetti after numberOfPieces pieces have been shown. | | run | Bool | true | Run the animation loop | | frameRate | Number \| undefined | undefined | The capped frame rate of the animation. | | tweenDuration | Number | 5000 | How fast the confetti is added | | tweenFunction | (currentTime: number, currentValue: number, targetValue: number, duration: number, s?: number) => number | easeInOutQuad | See tween-functions | | drawShape | (context: CanvasRenderingContext2D) => void | undefined | See below | | onConfettiComplete | (confetti: Confetti) => void | undefined | Called when all confetti has fallen off-canvas. |

drawShape()

Draw a custom shape for a particle. If not provided, defaults to a random selection of a square, circle or strip confetto. The function is called with the canvas context as a parameter and the Particle as the this context.

For example, to draw all spirals:

<Confetti
  drawShape={ctx => {
    ctx.beginPath()
    for(let i = 0; i < 22; i++) {
      const angle = 0.35 * i
      const x = (0.2 + (1.5 * angle)) * Math.cos(angle)
      const y = (0.2 + (1.5 * angle)) * Math.sin(angle)
      ctx.lineTo(x, y)
    }
    ctx.stroke()
    ctx.closePath()
  }}
/>