0.3.3 • Published 2 years ago

@react-cmpt/use-throttle v0.3.3

Weekly downloads
32
License
MIT
Repository
github
Last release
2 years ago

use-throttle

The throttled value / function hook for react

CI npm GitHub license minzip

Usage

Installation

yarn add @react-cmpt/use-throttle

codesandbox

Edit use-throttle-example

useThrottle

throttled value

returntypeexplain
valueanyReturns the new throttled value.
cancelfunctionThe clear timer function.
callPendingfunctionThe callback manually function.
import { useThrottle } from "@react-cmpt/use-throttle";

const Demo = ({ value }) => {
  const [tValue, { cancel, callPending }] = useThrottle(value, 200);

  // ...
};

useThrottleFn

throttled function

returntypeexplain
callbackfunctionThe new throttled function.
cancelfunctionThe clear timer function.
callPendingfunctionThe callback manually function.
import { useThrottleFn } from "@react-cmpt/use-throttle";

const Demo = () => {
  const { callback, cancel, callPending } = useThrottleFn(() => {
    console.log("click");
  }, 200);

  return <button onClick={callback}>++</button>;
};

useDebounce, useDebounceCallback -> use-debounce

Dev

# build package
yarn build

# tests
yarn test

# lint
yarn lint

License

MIT