Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

useThrottle

import { useCallback, useRef } from 'react'

export default function useThrottle(callback: (...args: unknown[]) => void, delay = 20) {
  const isThrottled = useRef(false)

  const throttledCallback = useCallback(
    (...args) => {
      if (isThrottled.current) return

      callback(args)
      isThrottled.current = true
      setTimeout(() => (isThrottled.current = false), delay)
    },
    [callback, delay]
  )

  return throttledCallback
}
Comment

PREVIOUS NEXT
Code Example
Javascript :: js spin wheel color 
Javascript :: javascript type 
Javascript :: Convert to String Explicitly 
Javascript :: Finding palindrome using for loop 
Javascript :: javascript function expressions 
Javascript :: javascript Remove Element from Inner Array 
Javascript :: javascript Display Undeclared Variable 
Javascript :: return number less than in 250 
Javascript :: javascript for...of with Sets 
Javascript :: javascript Undeclared objects are not allowed 
Javascript :: javascript Number() Method Used on Dates 
Javascript :: mui on node 
Javascript :: simple counter with react hook 
Javascript :: nodejs: http: router simple 
Javascript :: js regex find newlines 
Javascript :: javascript döngü dizisi 
Javascript :: Cntrlsss:$.Control-Ai 
Javascript :: phaser animation get progress 
Javascript :: regular expression a-z and 0-9 
Javascript :: _.isUndefined 
Javascript :: Move capital letters to the beginning 
Javascript :: get product 
Javascript :: Adding A Function To All Node Example With Javascript 
Javascript :: javascript prompts user to input 
Javascript :: javascript get date value from input 
Javascript :: Javascript Scrape content from a website source code 
Javascript :: react simple typewriter 
Javascript :: underscore.js 
Javascript :: get element by id angular 
Javascript :: chart.js 
ADD CONTENT
Topic
Content
Source link
Name
2+7 =