Svelte · Middle · Question 5 of 75
How do you read state inside $effect without making it a dependency?
import { untrack } from "svelte";
$effect(() => {
save(data, untrack(() => settings.format));
});- ✓Correct answer: Wrap the read in
untrack(() => ...) - 2Read it in
onMountinstead - 3Use
$state.snapshot, which also untracks
Explanation
The effect re-runs when data changes but not when settings.format changes.