@uplift-ltd/use-safe-timeout
v2.0.1
Published
Hook to set a timeout and clear it on unmount.
Downloads
226
Readme
@uplift-ltd/use-safe-timeout
Installation
npm i --save @uplift-ltd/use-safe-timeout
API
useSafeTimeout
Returns a function to cancel the timeout
import { useSafeTimeout } from "@uplift-ltd/use-safe-timeout";
function MyComponent() {
const setSafeTimeout = useSafeTimeout();
const cancelTimeout = setSafeTimeout(
() => console.log("I get called in 5s if component stays mounted!"),
5000
);
return <button onClick={cancelTimeout}>Cancel Timeout</button>;
}