Files
probo/apps/trust/src/hooks/useDelayedEffect.ts
Jonathan 55e85e5f67 Add trust center v2
Signed-off-by: Jonathan <contact@grafikart.fr>
2025-09-30 16:23:22 +02:00

20 lines
481 B
TypeScript

import { useEffect, useRef } from "react";
/**
* Hook to handle cleanup after a delay
*
* Used for disposing the graphQL query when the component unmounts
*/
export function useCleanup(callback: () => void, delay: number) {
const timer = useRef<ReturnType<typeof setTimeout>>(null);
useEffect(() => {
if (timer.current) {
clearTimeout(timer.current);
}
return () => {
timer.current = setTimeout(callback, delay);
};
}, [callback, delay]);
}