Signature
An event dispatcher function
EventDispatcher
The event name
The event detail data. Type depends on the event type in the
EventMapEvent options
Whether the event can be cancelled with
event.preventDefault()Returns
false if the event was cancelled with preventDefault(), otherwise trueUsage
Basic Event Dispatch
Create and dispatch simple events:Typed Event Dispatcher
Type your events for better IDE support and type safety:Cancelable Events
Create events that can be cancelled:Event Forwarding
Forward events from child components:Event Characteristics
No Bubbling
Unlike DOM events, component events created withcreateEventDispatcher do not bubble:
CustomEvent Details
Dispatched events areCustomEvent instances:
Migration to Svelte 5
In Svelte 5, component events are replaced with callback props:Notes
- Must be called during component initialization
- Events do not bubble - they only go one level up
- Events are
CustomEventinstances - The
detailproperty contains your event data - Return value indicates whether the event was cancelled
- Unlike DOM events, component events are synchronous
- In Svelte 5, prefer callback props over
createEventDispatcher
See Also
- Event handlers - Handle DOM and component events
- Component events - Legacy component events documentation
- Migration guide - Migrating to callback props