Back to Mantine

Use Throttled Callback

apps/mantine.dev/src/pages/hooks/use-throttled-callback.mdx

9.2.1596 B
Original Source

import { UseThrottledCallbackDemos } from '@docs/demos'; import { Layout } from '@/layout'; import { MDX_DATA } from '@/mdx';

export default Layout(MDX_DATA.useThrottledCallback);

Usage

The useThrottledCallback hook accepts a function and a wait time in milliseconds. It returns a throttled version of the function that will only be called at most once every wait milliseconds.

<Demo data={UseThrottledCallbackDemos.usage} />

Definition

tsx
function useThrottledCallback<T extends (...args: any[]) => any>(
  callback: T,
  wait: number
): (...args: Parameters<T>) => void;