@uplift-ltd/use-safe-timeout
TypeScript icon, indicating that this package has built-in type declarations

2.0.1 • Public • Published

@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>;
}

Readme

Keywords

none

Package Sidebar

Install

npm i @uplift-ltd/use-safe-timeout

Weekly Downloads

107

Version

2.0.1

License

MIT

Unpacked Size

6.08 kB

Total Files

11

Last publish

Collaborators

  • mariusc23