Important: This documentation covers Yarn 1 (Classic).
For Yarn 2+ docs and migration guide, see yarnpkg.com.

Package detail

use-cancelable-timeout

ardsh88MIT1.0.1

Declarative React hook for canceling a setTimeout callback

setTimeout, useTimeout, cancelable, cancel, timeout, hooks, react, hover, prefetch

readme

use-cancelable-timeout

npm version MIT license

A react hook for executing a function after a timeout, with an option to cancel it.

Install

npm install use-cancelable-timeout

 

Usage

import useCancelableTimeout from "use-cancelable-timeout";

function SimpleExample() {
  const [message, setMessage] = useState("Not hovered");

  const [onPointerEnter, onPointerLeave] = useCancelableTimeout(
    () => setMessage("Hovered for 1 second!"),
    1000,
  );

  return (
    <div onPointerEnter={onPointerEnter} onPointerLeave={onPointerLeave}>
      {message}
    </div>
  );
}

 

License

MIT © ardsh