0Pricing
Sveltejs Academy · Lesson

Custom Events with createEventDispatcher

Emit typed custom events from child components for parent to handle.

Why Custom Events

Child components communicate up by dispatching custom events the parent listens for.

Import the Dispatcher

Import createEventDispatcher from svelte and create one inside your script.

<script>
  import { createEventDispatcher } from "svelte";
  const dispatch = createEventDispatcher();
</script>

All lessons in this course

  1. on:click on:input on:submit
  2. Event Modifiers: preventDefault stopPropagation once
  3. Custom Events with createEventDispatcher
  4. Forwarding Events with on:click
← Back to Sveltejs Academy