Skip to main content
When used inside a $derived or $effect, any state read inside fn will not be treated as a dependency.

Parameters

fn
() => T
required
A function to execute without tracking dependencies. Any reactive state accessed within this function will not cause the containing effect or derived to re-run

Returns

result
T
The return value of the fn function

Examples

Saving data with timestamp

Reading state without creating dependency

Conditional dependency

Preventing infinite loops

Accessing context without dependency

Use cases

  • Logging: Read reactive state for logging purposes without creating unnecessary dependencies
  • Timestamps: Add metadata (like timestamps) that shouldn’t trigger re-runs
  • Conditional dependencies: Only track certain values when specific conditions are met
  • Breaking circular dependencies: Update state within an effect that reads related state
  • Performance optimization: Prevent unnecessary reactivity for values that don’t need to trigger updates

Notes

  • untrack() only affects dependency tracking, not the execution of the function
  • The function passed to untrack() is executed immediately and synchronously
  • This is particularly useful in $effect and $derived contexts where automatic dependency tracking occurs
  • State reads inside untrack() still return the current reactive value, they just don’t create dependencies