Dhairya Shah
Dhairya Shah's Blog

Dhairya Shah's Blog

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

Subscribe to my newsletter and never miss my upcoming articles

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