Use directive syntax in Svelte
📖 Scenario: You are building a simple Svelte app that shows a list of tasks. You want to display only the tasks that are marked as important.
🎯 Goal: Create a Svelte component that uses the {#if} directive to show only important tasks from a list.
📋 What You'll Learn
Create an array called
tasks with objects containing id, name, and important propertiesCreate a boolean variable called
showImportantOnly set to trueUse the
{#if} directive inside a {#each} block to display only tasks where important is true when showImportantOnly is trueAdd a button that toggles
showImportantOnly between true and false💡 Why This Matters
🌍 Real World
Filtering lists based on user preferences is common in apps like to-do lists, shopping lists, and email clients.
💼 Career
Understanding Svelte directives and reactive variables is essential for building interactive web apps efficiently.
Progress0 / 4 steps