use-cancelable-timeout
v1.0.1
Published
Declarative React hook for canceling a setTimeout callback
Downloads
97
Maintainers
Readme
use-cancelable-timeout
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