fix: only trigger confetti when watching live
This commit is contained in:
20
src/hooks/usePreviousValue.ts
Normal file
20
src/hooks/usePreviousValue.ts
Normal file
@ -0,0 +1,20 @@
|
||||
import { useEffect, useRef } from "react";
|
||||
|
||||
/**
|
||||
* On each render returns the previous value of the given variable/constant.
|
||||
*/
|
||||
const usePreviousValue = <TValue>(value?: TValue): TValue | undefined => {
|
||||
const prevValue = useRef<TValue>();
|
||||
|
||||
useEffect(() => {
|
||||
prevValue.current = value;
|
||||
|
||||
return () => {
|
||||
prevValue.current = undefined;
|
||||
};
|
||||
});
|
||||
|
||||
return prevValue.current;
|
||||
};
|
||||
|
||||
export default usePreviousValue;
|
Reference in New Issue
Block a user