fix: only trigger confetti when watching live

This commit is contained in:
Alejandro Gomez
2023-07-09 01:11:45 +02:00
parent aaa2e26bd9
commit e13e3bccf6
2 changed files with 25 additions and 1 deletions

View 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;