CHAPTER 09
Beginner
Props and Component Communication
Updated: May 18, 2026
5 min read
# CHAPTER 9
Props and Component Communication
1. Chapter Introduction
Components become truly powerful when they can talk to each other. In Svelte, data flows down via props (export let), and events flow up via createEventDispatcher or bind: for two-way binding. This chapter covers the complete Svelte component communication model.
2. Learning Objectives
-
Pass data from parent to child using
export let.
- Dispatch custom events from child to parent.
-
Use
bind:for two-way prop binding.
-
Spread props using
{...object}.
- Build a multi-component architecture.
3. Passing Props (Parent → Child)
svelte
svelte
4. Child-to-Parent: Events
svelte
svelte
5. Two-Way Binding with bind:
svelte
svelte
6. Event Forwarding
To forward native DOM events from a child to the parent, useon:click without a handler:
svelte
svelte
7. Spread Props ($$props and $$restProps)
svelte
svelte
8. Common Mistakes
-
Mutating props in the child: Never modify an
export letprop inside the child. Usebind:for two-way or dispatch an event for the parent to handle.
-
Forgetting
export:let nameis private local state.export let nameis a prop.
9. MCQs
Question 1
How do you declare a prop in Svelte?
Question 2
How do you set a default prop value?
Question 3
What is the data flow direction for props?
Question 4
What Svelte function enables custom event dispatching?
Question 5
How do you access dispatched event data in the parent?
Question 6
What does bind:value={quantity} on a child component do?
Question 7
What does {...product} do when used on a component?
Question 8
What is $$restProps?
Question 9
How do you forward a click event from a child <button> to the parent without a handler?
10. Interview Questions
-
Q: Compare Svelte's prop/event pattern with Angular's
@Input/@Output.
-
Q: When would you use
bind:instead ofon:dispatch?
11. Summary
Svelte's component communication is elegant:export let for props flowing down, createEventDispatcher for events flowing up, and bind: for convenient two-way binding. The $$restProps pattern enables building truly generic, flexible components that forward all HTML attributes.