Svelte · Junior · Question 31 of 76

How does a child component tell its parent that something happened in Svelte 5?

<!-- Child.svelte -->
<script>
  let { onsave } = $props();
</script>

<button onclick={() => onsave("data")}>Save</button>

Explanation

createEventDispatcher is deprecated in Svelte 5. Callback props are simpler and fully typed.

Further reading

Problem with a question

Svelte · Junior · question 31

Test yourself

Take the Svelte · Junior quiz: questions and options are shuffled, and you get a review of your mistakes at the end.

Take this quiz