UNPKG

react-reuse-hooks

Version:

A collection of 30+ production-ready reusable React hooks for web apps, covering state, effects, media, forms, and utilities.

13 lines (9 loc) 347 B
import { useState, useEffect } from "react"; export function useThrottle(value, limit) { const [throttledValue, setThrottledValue] = useState(value); useEffect(() => { const handler = setTimeout(() => setThrottledValue(value), limit); return () => clearTimeout(handler); }, [value, limit]); return throttledValue; }