Complete the code to create a context key using Svelte's setContext.
import { setContext } from 'svelte'; const key = [1]; setContext(key, 'shared data');
Using Symbol('myKey') creates a unique key for context, avoiding conflicts.
Complete the code to get the shared context data in a child component using getContext.
import { getContext } from 'svelte'; const key = Symbol('myKey'); const data = [1](key);
setContext instead of getContext to retrieve data.getContext retrieves the data set by setContext using the same key.
Fix the error in the code to share data without prop drilling by correctly setting and getting context.
/* Parent.svelte */ import { setContext } from 'svelte'; const key = Symbol('myKey'); let sharedData = 'shared data'; setContext(key, [1]); /* Child.svelte */ import { getContext } from 'svelte'; const key = Symbol('myKey'); const data = getContext(key);
The parent must set context with a variable sharedData that holds the data to share.
Fill both blanks to create and use context to share a count value without prop drilling.
import { setContext, getContext } from 'svelte'; /* Parent.svelte */ const key = [1]; setContext(key, 10); /* Child.svelte */ const count = [2](key);
setContext to get data.Use a unique Symbol as the key and getContext to retrieve the value.
Fill all three blanks to share a reactive store via context and access it in a child component.
import { writable } from 'svelte/store'; import { setContext, getContext } from 'svelte'; const key = [1]; const count = [2](0); setContext(key, count); // In child component const countStore = [3](key);
readable instead of writable for a store that changes.getContext to access the store.Create a unique Symbol key, a writable store, set it in context, and get it in the child.