Skip to content
GaudiGaudi Design System home

Search documentation

Search every page, heading and paragraph.

useDebounceCallback

A debounced function with cancel and flush.

HooksState@gaudi/design-system/hooks/state/use-debounce-callbackView in StorybookSource

Runs the latest callback once, delay ms after the last call, with the latest arguments: autosave, search requests and resize work. Pending work is cancelled on unmount.

Usage

import { useDebounceCallback } from '@gaudi/design-system/hooks';
const save = useDebounceCallback((text) => saveDraft(text), 800);<Textarea onChange={(event) => save(event.target.value)} onBlur={save.flush} />

Examples

Autosave a draft

Storybook

API

2 options
2 return values

Accessibility

For autosave, show and announce the saved state once the debounced save finishes, and flush on blur so work is not lost.

Notes

  • createDebouncer(callback, delay) is exported for non-React code.