Component composition
📖 Scenario: You are building a simple Svelte app that shows a list of fruits with their colors. You want to split the UI into smaller parts for better organization.
🎯 Goal: Create two Svelte components: FruitItem.svelte to show one fruit and its color, and FruitList.svelte to show the list of fruits using FruitItem. Compose them so the app displays all fruits with their colors.
📋 What You'll Learn
Create a
FruitItem.svelte component that accepts name and color as props and displays them.Create a
FruitList.svelte component that has a list of fruits as an array of objects with name and color.Use
FruitItem inside FruitList to render each fruit.Ensure the main app file
App.svelte renders FruitList.💡 Why This Matters
🌍 Real World
Component composition is how you build complex user interfaces by combining small, reusable parts. This makes your code easier to manage and update.
💼 Career
Understanding component composition is essential for working with modern frontend frameworks like Svelte, React, or Vue. It is a core skill for frontend developers.
Progress0 / 4 steps