use-cancelable-timeout

1.0.1 • Public • Published

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

Versions

Current Tags

  • Version
    Downloads (Last 7 Days)
    • Tag
  • 1.0.1
    20
    • latest

Version History

  • Version
    Downloads (Last 7 Days)
    • Published
  • 1.0.1
    20
  • 1.0.0
    1

Package Sidebar

Install

npm i use-cancelable-timeout

Weekly Downloads

21

Version

1.0.1

License

MIT

Unpacked Size

9.7 kB

Total Files

12

Last publish

Collaborators

  • ardsh