Why props pass data to children in Svelte
📖 Scenario: You are building a simple Svelte app that shows a greeting message. The main component will pass the name to a child component using props.
🎯 Goal: Learn how to pass data from a parent component to a child component using props in Svelte.
📋 What You'll Learn
Create a parent component with a variable
userName set to 'Alice'Create a child component that accepts a prop called
namePass the
userName from the parent to the child using propsDisplay the greeting message in the child component using the passed prop
💡 Why This Matters
🌍 Real World
Passing data with props is how components share information in real Svelte apps, like sending user info or settings from a main page to smaller parts.
💼 Career
Understanding props is essential for building interactive, modular web apps with Svelte, a popular modern framework used in many companies.
Progress0 / 4 steps