Skip to content

Bring debounce & throttle of lodash version to react hooks

Notifications You must be signed in to change notification settings

Frezc/use-lodash-debounce-throttle

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

13 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Bring debounce & throttle of lodash version to react-hooks.

useDebounce & useThrottle will auto create, update and cancel debounced & throttled instance, so you do not need to cancel manually.

demo

https://frezc.github.io/use-lodash-debounce-throttle/

usage

install

yarn add use-lodash-debounce-throttle

useDebounce

import { useDebounce } from 'use-lodash-debounce-throttle';

const Com = () => {
  const debouncedChange = useDebounce((v) => {
    postUpdate();
  }, 500, { maxWait: 2000 });

  return (
    <input
      type="text"
      onChange={(e) => {
        debouncedChange(e.target.value)
      }}
    />
  )
}

useThrottle

import { useThrottle } from 'use-lodash-debounce-throttle';

const Com = () => {
  const debouncedChange = useThrottle((v) => {
    sendMessage();
  }, 500, { leading: false });

  return (
    <input
      type="text"
      onChange={(e) => {
        debouncedChange(e.target.value)
      }}
    />
  )
}

API

DEV

yarn install
yarn start

About

Bring debounce & throttle of lodash version to react hooks

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published