Overview:
The react-canvas-confetti is a React component that allows users to integrate the canvas-confetti library into their React applications. This component provides an interface for creating and controlling confetti animations on a canvas element. Users can customize various parameters such as the number of confetti, angle, spread, start velocity, decay, gravity, drift, and origin. The react-canvas-confetti component offers two use cases: using callbacks to control the animation from the parent component or directly manipulating the component’s props to control the animation.
Features:
- Callback for Getting the Canvas-Confetti Instance: Users can use the
confettiprop to get the canvas-confetti instance into the parent component, allowing them to control the animation programmatically. - Animation Control Props: Users can use the
fireprop to start the animation, theresetprop to reset all animations at once, and theonFire,onDecay, andonResetcallbacks to trigger custom actions on animation events. - Canvas Size Control: Users can set the width and height of the canvas using the
widthandheightprops, or they can use theclassNameandstyleprops for alternative ways to control canvas sizes. - Customization of Confetti Parameters: Users can customize various parameters of the confetti animation, such as the number of confetti, angle, spread, start velocity, decay, gravity, drift, ticks, and origin.
Installation:
To install the react-canvas-confetti component, make sure you have React already installed as a peer dependency. Then, you can install the component via npm by running the following command:
npm install react-canvas-confetti
Summary:
The react-canvas-confetti component provides a convenient way to integrate the canvas-confetti library into React applications. It offers various features such as animation control props, customization of confetti parameters, and callbacks for interacting with the animation from the parent component. With the react-canvas-confetti component, users can easily create and control confetti animations on a canvas element in their React applications.