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));
});

Explanation

The effect re-runs when data changes but not when settings.format changes.

Further reading

Problem with a question

Svelte · Middle · question 5

Test yourself

Take the Svelte · Middle quiz: questions and options are shuffled, and you get a review of your mistakes at the end.

Take this quiz