@tremendous/help
    Preparing search index...

    Function useSetTimeout

    • Custom hook that returns a safe version of setTimeout which will clear all timeouts when the component unmounts.

      This hook ensures that any timeouts set within the component are cleared when the component unmounts, avoiding potential memory leaks.

      Parameters

      • Optionaldependencies: DependencyList = []

        List of dependencies for the effect that clears timeouts.

      Returns (callback: () => void, delay: number) => Timeout

      • A safe version of setTimeout.
      const safeSetTimeout = useSetTimeout();

      useEffect(() => {
      const timeoutId = safeSetTimeout(() => {
      console.log('This will run after 1 second');
      }, 1000);
      return () => {
      clearTimeout(timeoutId); // Optional, since useSetTimeout will clear it on unmount
      };
      }, [safeSetTimeout]);