Hooks
Functions
useInterval
This hook provides an easy way to debounce any function, ensuring that it only executes after a specified delay.
Example
import useInterval from '@/utils/hooks/useInterval'
const Example = () => {
const [count, setCount] = useState(0)
useInterval(() => {
setCount((prevCount) => prevCount + 1)
}, 1000)
return <div>Count: {count}</div>;
};
export default Example
Params
| param | Description | Type | Default |
|---|---|---|---|
| callback | The function to be executed at each interval. | () => void | - |
| delay | The delay between each execution of the callback in milliseconds. If null, the interval is paused. | number | null | - |
API
Return
| return | Description | Type | Default |
|---|---|---|---|
| intervalRef | A ref object that holds the interval ID, which can be used for manual management of the interval. | React.MutableRefObject | - |