Fix redundant confetti on LYS task congrats page (#47838)
* Add useRef to ensure confetti is only trigerred once * Changelog
This commit is contained in:
parent
977f8289af
commit
012f0d3418
|
@ -0,0 +1,4 @@
|
|||
Significance: patch
|
||||
Type: fix
|
||||
|
||||
Added useRef to ensure confetti animation is only run once
|
|
@ -2,7 +2,7 @@
|
|||
* External dependencies
|
||||
*/
|
||||
import confetti from 'canvas-confetti';
|
||||
import { useEffect } from '@wordpress/element';
|
||||
import { useEffect, useRef } from '@wordpress/element';
|
||||
|
||||
/**
|
||||
* Note: This was copied over from https://github.com/Automattic/wp-calypso/blob/a39539547780871d0371a20fcf21c767a86a1010/packages/components/src/confetti/index.ts
|
||||
|
@ -83,9 +83,12 @@ export const ConfettiAnimation = ( {
|
|||
delay = 0,
|
||||
colors = COLORS,
|
||||
} ) => {
|
||||
const hasRun = useRef( false );
|
||||
|
||||
useEffect( () => {
|
||||
if ( trigger ) {
|
||||
if ( ! hasRun.current && trigger ) {
|
||||
setTimeout( () => fireConfetti( colors ), delay );
|
||||
hasRun.current = true;
|
||||
}
|
||||
}, [ trigger, delay, colors ] );
|
||||
|
||||
|
|
|
@ -0,0 +1,4 @@
|
|||
Significance: patch
|
||||
Type: fix
|
||||
|
||||
Added useRef to ensure confetti animation is only run once
|
Loading…
Reference in New Issue