useTimeout

Update value after a given time.

Usage

import { useTimeout } from "@reactuses/core";

const Demo = () => {
  const [isPending, start, cancel] = useTimeout(5000);

  return (
    <div>
      <div>Pending: {JSON.stringify(isPending)}</div>
      <button
        onClick={() => {
          start();
        }}
      >
        Start Again
      </button>
      <button
        onClick={() => {
          cancel();
        }}
      >
        Cancel
      </button>
    </div>
  );
};

Example

Pending: false

Type Declarations

export default function useTimeout(
  ms?: number,
  options?: UseTimeoutFnOptions
): Stoppable