setContext in Svelte?setContext lets you share data or stores from a parent component to its children without passing props manually.
You use getContext with the same key used in setContext. Then you can subscribe or use the store directly.
Context avoids prop drilling, making code cleaner and easier to maintain when many nested components need the same store.
You can share any JavaScript value, including stores, functions, objects, or primitives.
By decoupling data sharing from component hierarchy, components can be reused without needing to pass many props explicitly.
setContext is used to provide data or stores to child components.
Child components use getContext with the same key to access the store.
Context avoids prop drilling by sharing data without passing props through every level.
Svelte's context API can share any JavaScript value, including functions.
You must use getContext with the key used in setContext to access the store.