1.0.1 • Published 5 years ago
use-cancelable-timeout v1.0.1
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