Which scenario is best suited for using context instead of stores in Svelte?
Think about the scope and lifetime of data when choosing between context and stores.
Context is ideal for passing data down a specific component subtree without prop drilling. Stores are better for global reactive data accessible anywhere.
Consider a Svelte app where a store and a context both hold a count value. If the store's count changes, which components update? What about if the context's count changes?
Remember how reactivity works with stores and context in Svelte.
Stores notify all subscribers anywhere in the app. Context updates only affect components that consume that context within the subtree.
Which option shows the correct way to set and get context in Svelte components?
Check official Svelte API for context functions.
setContext is used in a parent to provide data, and getContext is used in a child to consume it.
A Svelte component subscribes to a writable store but does not update when the store value changes. What is the most likely cause?
Check if the component and the store share the same instance.
If the component imports a different store instance than the one updated, it won't react to changes.
Given the following Svelte setup:
Parent.svelte:Child.svelte: Context count: {contextCount}
Store count: {storeCount}
What is the output after clicking the button twice?
Remember context is static unless reset; store updates reactively change subscribed values.
The context value is set once to 10 and does not change. The store starts at 0 and increments twice to 2.