UNPKG

react-custom-hooks-utils

Version:

This library contains a collection of reusable React custom hooks to simplify state management, side effects, and user interactions.

15 lines (12 loc) 316 B
import { useEffect, useRef } from 'react'; function useThrottle(callback, delay) { const lastCall = useRef(0); return (...args) => { const now = new Date().getTime(); if (now - lastCall.current >= delay) { lastCall.current = now; callback(...args); } }; } export default useThrottle;