Complete the code to create a writable store in Svelte.
import { [1] } from 'svelte/store'; const count = [1](0);
readable instead of writable when you want to update the store.The writable function creates a store you can update and subscribe to.
Complete the code to set a context value with a store in a Svelte component.
import { setContext } from 'svelte'; import { writable } from 'svelte/store'; const count = writable(0); setContext('[1]', count);
The key used in setContext should match the name you want to identify the store by. Here, 'count' is used as the key.
Fix the error in the child component to get the store from context and subscribe to it.
import { getContext } from 'svelte'; const count = getContext([1]); count.subscribe(value => { console.log(value); });
The getContext function requires the exact string key used in setContext. It must be a string literal like 'count'.
Fill both blanks to create a derived store from a context store and use it in the component.
import { getContext } from 'svelte'; import { [1] } from 'svelte/store'; const count = getContext('count'); const doubled = [2](count, $count => $count * 2);
writable or readable instead of derived.derived from the correct module.The derived function creates a new store based on another store's value. You import and use derived here.
Fill all three blanks to update a context store value inside a component.
import { getContext } from 'svelte'; const count = getContext('count'); function increment() { count.[1](n => n [2] 1); } <button on:click=[3]>Increment</button>
set instead of update when incrementing.The update method changes the store value based on the current value. The function increment is called on button click.