0
0
Svelteframework~10 mins

getContext in Svelte - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to get a context value inside a Svelte component.

Svelte
import { getContext } from 'svelte';

const value = getContext([1]);
Drag options to blanks, or click blank then click option'
A'myKey'
BsetContext
Ccontext
DuseContext
Attempts:
3 left
💡 Hint
Common Mistakes
Passing a function or variable instead of a string key.
Using setContext instead of getContext.
2fill in blank
medium

Complete the code to import the correct function to retrieve context in Svelte.

Svelte
import { [1] } from 'svelte';
Drag options to blanks, or click blank then click option'
AsetContext
BcreateContext
CuseContext
DgetContext
Attempts:
3 left
💡 Hint
Common Mistakes
Confusing getContext with setContext.
Using React-like functions such as useContext.
3fill in blank
hard

Fix the error in this code that tries to get context but uses the wrong key.

Svelte
const theme = getContext([1]);
Drag options to blanks, or click blank then click option'
A'Theme'
Btheme
C'theme'
DgetContext
Attempts:
3 left
💡 Hint
Common Mistakes
Using a variable instead of a string key.
Wrong capitalization of the key string.
4fill in blank
hard

Fill both blanks to get a context value and log it in a Svelte component.

Svelte
import { [1] } from 'svelte';

const data = [2]('userData');
console.log(data);
Drag options to blanks, or click blank then click option'
AgetContext
BsetContext
DuseContext
Attempts:
3 left
💡 Hint
Common Mistakes
Using setContext instead of getContext.
Not importing getContext before using it.
5fill in blank
hard

Fill all three blanks to get a context value and use it in a reactive statement.

Svelte
import { [1] } from 'svelte';

const count = [2]('countKey');

$: doubled = count [3] 2;
Drag options to blanks, or click blank then click option'
AgetContext
C*
D+
Attempts:
3 left
💡 Hint
Common Mistakes
Using + instead of * for multiplication.
Not importing getContext before use.