Svelte & SvelteKit (50 Qs)•Part 3: Advanced Internals, Scale & Production Architecture (Senior / Lead)
Context API in Svelte: `setContext` vs `getContext`.
senior LevelSystem DesignSvelte 5HTTP & REST APIs
In Simple Words:
setContext(key, value) and getContext(key) share state between parent and deeply nested descendant components without prop-drilling.
- Lifecycle Rule: Must be called during component initialization (synchronous execution of
<script>), not inside event handlers or asynchronous timeouts. - Key Pattern: Use unique JavaScript
Symbol()keys to prevent accidental key collisions in large component libraries.