Svelte · Middle · Question 22 of 75
How do you make context reactive?
<script>
import { setContext } from "svelte";
let user = $state({ name: "Ann" });
setContext("user", user);
</script>- ✓Correct answer: Pass a
$stateobject (or a class instance with$statefields) and mutate it; consumers see updates - 2Context is always reactive, even for primitives
- 3Call
setContextagain whenever the value changes
Explanation
Reassigning the variable user = {...} doesn't update context, because the context holds the original object.