Why context shares data without prop drilling
📖 Scenario: Imagine you have a family tree app where the grandparent wants to share a message with the grandchild. Instead of passing the message through the parent, we use context to share it directly.
🎯 Goal: Build a simple Svelte app that uses context to share a message from a grandparent component to a grandchild component without passing props through the parent.
📋 What You'll Learn
Create a
Grandparent.svelte component that sets a context value called message with the text 'Hello from Grandparent!'Create a
Parent.svelte component that does not receive or pass any propsCreate a
Grandchild.svelte component that reads the message from context and displays itUse Svelte's
setContext and getContext functions properly💡 Why This Matters
🌍 Real World
Context sharing is useful in apps where many components need access to the same data, like user info or theme settings, without passing props through every level.
💼 Career
Understanding context is important for building clean, maintainable component-based apps in Svelte and other frameworks.
Progress0 / 4 steps