Complete the code to create a writable store in Svelte.
import { [1] } from 'svelte/store'; const count = [1](0);
In Svelte, writable creates a store that can be updated. This is used for reactive state.
Complete the code to set a context value in a Svelte component.
import { setContext } from 'svelte'; setContext('[1]', 42);
The first argument to setContext is a key string to identify the context value.
Fix the error in the code to get a context value in a Svelte component.
import { [1] } from 'svelte'; const count = getContext('count');
getContext is used to retrieve a value set by setContext.
Fill both blanks to create a derived store from two writable stores.
import { writable, derived } from 'svelte/store'; const a = writable(1); const b = writable(2); const sum = [1]([a, b], ([$a, $b]) => $a [2] $b);
writable instead of derived.derived creates a store based on others. The function adds the two values.
Fill all three blanks to decide when to use context or stores in Svelte.
/* Use context when you want to pass data [1] components without prop drilling. Use stores when you want [2] reactive state shared [3] many components. */
Context passes data between components without props.
Stores hold a reactive state shared across many components.
