Skip to content
GaudiGaudi Design System home

Search documentation

Search every page, heading and paragraph.

useEventCallback

A stable function that always calls the latest callback.

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

Pass handlers to effects, subscriptions and memoised children without re-running them when an inline callback changes. Call it from events and effects, not during render.

Usage

import { useEventCallback } from '@gaudi/design-system/hooks';
const onMessage = useEventCallback((message) => setLog((log) => [...log, message]));useEffect(() => socket.subscribe(onMessage), [onMessage]);

Examples

Fresh state, stable subscription

Storybook

API

1 option
1 return value

Accessibility

No direct accessibility impact; it keeps listeners stable so focus and announcements are not reset by re-subscriptions.

Notes

  • Do not call the returned function during render.