React Hookers - v6.3.0
    Preparing search index...

    Function useTimeout

    • Returns an API that delays invoking a callback until after a timeout.

      The delayed invocation is automatically cancelled when the component unmounts.

      The timeout should be started or stopped only after the component has mounted. Before that, calling either function is a no-op.

      Returns [schedule: Schedule, cancel: () => void]

      const [schedule, cancel] = useTimeout();

      useEffect(() => {
      // Cancels any pending timeout and schedules a new call
      schedule(
      (a, b) => {
      doSomething(a, b);
      },
      500, // Timeout delay in milliseconds
      a, b, // Arguments passed to the callback
      );

      // Cancels the last scheduled call
      cancel();
      }, []);