Complete the code to set a context value in a Svelte component.
<script> import { setContext } from 'svelte'; const key = 'user'; const user = { name: 'Alice' }; setContext([1], user); </script>
The setContext function uses a key variable to identify the context. Here, key holds the string 'user', so it should be passed as the first argument.
Complete the code to import the correct function for setting context in Svelte.
<script> import [1] from 'svelte'; </script>
getContext instead of setContext.useContext.To set context in Svelte, you import setContext from 'svelte'.
Fix the error in the code that tries to set context with a string key directly.
<script> import { setContext } from 'svelte'; setContext([1], { name: 'Bob' }); </script>
The key for setContext can be a string literal like 'user'. Using a variable without declaration causes an error.
Fill both blanks to set context with a key and a value object.
<script> import { setContext } from 'svelte'; const [1] = 'theme'; const [2] = { color: 'blue' }; setContext(themeKey, themeValue); </script>
The variables themeKey and themeValue are declared and then used in setContext.
Fill all three blanks to set context with a key, a value, and then retrieve it in a child component.
<script> import { setContext, getContext } from 'svelte'; const [1] = 'auth'; const [2] = { loggedIn: true }; setContext(authKey, authValue); const userStatus = getContext([3]); </script>
getContext.First, authKey and authValue are declared and used in setContext. Then getContext uses authKey to retrieve the value.