Code Monkey home page Code Monkey logo

use-throttle's Introduction

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

option type default explain
value any - The value to throttle.
wait number 0 The number of milliseconds to throttle invocations to.
options leading boolean false Specify invoking on the leading edge of the timeout.
customizer function - The function to customize comparisons.
return type explain
value any Returns the new throttled value.
cancel function The clear timer function.
callPending function The callback manually function.
import { useThrottle } from "@react-cmpt/use-throttle";

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

  // ...
};

useThrottleFn

throttled function

option type default explain
fn function - The function to throttle.
wait number 0 The number of milliseconds to throttle invocations to.
options leading boolean false Specify invoking on the leading edge of the timeout.
return type explain
callback function The new throttled function.
cancel function The clear timer function.
callPending function The 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

use-throttle's People

Contributors

dependabot[bot] avatar lgtm-com[bot] avatar wangcch avatar

Stargazers

 avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

use-throttle's Issues

Default value for `leading` option?

In the readme, it doesn't say what the default option for leading is. I think it's false. Should someone add the default value to the docs?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.