react-confetti vs canvas-confetti vs confetti-js vs vue-confetti
JavaScript Confetti Libraries Comparison
1 Year
react-confetticanvas-confetticonfetti-jsvue-confettiSimilar Packages:
What's JavaScript Confetti Libraries?

These libraries provide developers with easy-to-use tools for adding confetti effects to web applications. Confetti effects are often used to enhance user experience during celebrations, achievements, or special events, creating a visually appealing and engaging atmosphere. Each library has its own unique features and is tailored for different frameworks or vanilla JavaScript, allowing developers to choose based on their specific needs and project requirements.

Package Weekly Downloads Trend
Github Stars Ranking
Stat Detail
Package
Downloads
Stars
Size
Issues
Publish
License
react-confetti2,487,9391,605220 kB3a month agoMIT
canvas-confetti787,47711,32092.3 kB36a year agoISC
confetti-js33,00361156.2 kB17-MIT
vue-confetti16,31823649.5 kB19-MIT
Feature Comparison: react-confetti vs canvas-confetti vs confetti-js vs vue-confetti

Customization

  • react-confetti:

    react-confetti provides props for customization, allowing developers to set colors, number of particles, and duration of the effect. This makes it flexible for different scenarios while maintaining ease of use within React components.

  • canvas-confetti:

    canvas-confetti allows extensive customization options, including colors, shapes, and sizes of the confetti particles. Developers can easily tweak parameters to create unique visual effects that match their application's theme.

  • confetti-js:

    confetti-js offers basic customization options, such as colors and particle count, but is more limited compared to canvas-confetti. It is designed for simplicity, making it easy to implement without extensive configuration.

  • vue-confetti:

    vue-confetti allows customization through props, enabling developers to adjust colors, particle sizes, and animation duration. It integrates well with Vue's reactive properties, making it easy to adapt the confetti effect based on application state.

Performance

  • react-confetti:

    react-confetti is designed to work efficiently within React's rendering cycle, minimizing unnecessary re-renders. It leverages React's virtual DOM for performance, ensuring smooth animations even in dynamic applications.

  • canvas-confetti:

    canvas-confetti is optimized for performance, using the HTML5 canvas element to render confetti efficiently. It can handle a large number of particles without significant performance degradation, making it suitable for high-demand applications.

  • confetti-js:

    confetti-js is lightweight and performs well for basic confetti effects. However, it may not be as efficient as canvas-confetti for complex animations or large particle counts, so it's best for simpler use cases.

  • vue-confetti:

    vue-confetti is optimized for Vue applications, ensuring that the confetti effect performs well without impacting the overall performance of the Vue app. It takes advantage of Vue's reactivity for efficient updates.

Integration

  • react-confetti:

    react-confetti is specifically built for React applications, providing a component-based approach that fits naturally into React's architecture. This makes it easy to use alongside other React components and libraries.

  • canvas-confetti:

    canvas-confetti can be easily integrated into any JavaScript project, making it versatile for various frameworks or plain JavaScript applications. It does not rely on any specific framework, allowing for broad usage.

  • confetti-js:

    confetti-js is also framework-agnostic, making it simple to include in any web project. Its straightforward API allows for quick integration without the need for complex setup.

  • vue-confetti:

    vue-confetti is tailored for Vue.js, allowing for seamless integration into Vue components. It utilizes Vue's lifecycle hooks, making it a natural choice for Vue developers.

Ease of Use

  • react-confetti:

    react-confetti is straightforward for React developers, with props that can be easily managed within the component state. Its integration with React makes it intuitive for those familiar with the framework.

  • canvas-confetti:

    canvas-confetti is user-friendly, with a clear API that allows developers to implement confetti effects with minimal code. However, some customization may require a deeper understanding of the canvas API.

  • confetti-js:

    confetti-js is designed for ease of use, with a simple API that allows developers to get started quickly without needing extensive knowledge of JavaScript or animations.

  • vue-confetti:

    vue-confetti is easy to use for Vue developers, providing a simple way to add confetti effects through props and Vue's reactive system. It requires minimal setup, making it accessible for all skill levels.

Community and Support

  • react-confetti:

    react-confetti benefits from the large React community, with plenty of resources, tutorials, and examples available. This support makes it easier for developers to troubleshoot and enhance their implementations.

  • canvas-confetti:

    canvas-confetti has a growing community and is well-documented, providing resources and examples that help developers implement and customize the library effectively.

  • confetti-js:

    confetti-js has a smaller community but offers basic documentation. It is suitable for quick implementations but may lack extensive support for complex use cases.

  • vue-confetti:

    vue-confetti is supported by the Vue community, which provides documentation and examples. While it may not be as widely used as other libraries, it is still a solid choice for Vue developers.

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

    Select react-confetti if you are building a React application and want a library that integrates seamlessly with React's component lifecycle. It allows for easy state management and is designed to work well with React's rendering model, making it perfect for React-based projects.

  • canvas-confetti:

    Choose canvas-confetti if you need a lightweight and highly customizable confetti effect that works with plain JavaScript. It offers great performance and flexibility, making it suitable for a variety of use cases, including games and interactive applications.

  • confetti-js:

    Opt for confetti-js if you are looking for a simple, easy-to-use library that provides a straightforward API for creating confetti effects. It is ideal for quick implementations and works well in projects where minimal configuration is desired.

  • vue-confetti:

    Choose vue-confetti if you are developing a Vue.js application. This library is specifically designed for Vue, providing a simple way to incorporate confetti effects while leveraging Vue's reactivity system, making it a great choice for Vue developers.

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()
  }}
/>