Function createEventDispatcher

  • Creates an event dispatcher that can be used to dispatch component events. Event dispatchers are functions that can take two arguments: name and detail.

    Component events created with createEventDispatcher create a CustomEvent. These events do not bubble. The detail argument corresponds to the CustomEvent.detail property and can contain any type of data.

    The event dispatcher can be typed to narrow the allowed event names and the type of the detail argument:

    const dispatch = createEventDispatcher<{
    loaded: never; // does not take a detail argument
    change: string; // takes a detail argument of type string, which is required
    optional: number | null; // takes an optional detail argument of type number
    }>();

    https://svelte.dev/docs/svelte#createeventdispatcher

    Type Parameters

    • EventMap extends Record<string, any> = any

    Returns EventDispatcher<EventMap>