Dhairya Shah
Dhairya Shah's Blog

Follow

Dhairya Shah's Blog

Follow
How to create confetti in React JS

How to create confetti in React JS

Dhairya Shah's photo
Dhairya Shah
·Sep 6, 2022·

1 min read

Play this article

In this article, I will show you the easy and simple way to create confetti in React.

First, install the following dependency:

npm i canvas-confetti

After installing the above package, import it into your React application:

import confetti from 'canvas-confetti';

To create confetti using the package, create the following function:

const handleConfetti = () => {
    confetti();
 };

Now create a button with the onClick event:

<button onClick={handleConfetti}>Show Confetti</button>

This will create amazing and satisfying confetti 🎉.

Check out the live version:


Thanks for reading

Follow me on Twitter

Thanks for reading!

 
Share this