Executes a function without tracking signal dependencies.
import { untrack } from '@barefootjs/client'
untrack<T>(fn: () => T): TReturns the value produced by fn.
#Basic Usage
const [count, setCount] = createSignal(0)
const [name, setName] = createSignal('Alice')
createEffect(() => {
// count() IS tracked — this effect re-runs when count changes
console.log('count:', count())
// name() is NOT tracked — changing name alone won't trigger this effect
console.log('name:', untrack(() => name()))
})
setCount(1) // Effect re-runs
setName('Bob') // Effect does NOT re-run#When to Use
#Read without subscribing
createEffect(() => {
// Re-run only when items change, not when sortOrder changes
const sorted = [...items()].sort(untrack(() => sortOrder()) === 'asc' ? compare : reverseCompare)
setDisplayList(sorted)
})#Log without dependencies
createEffect(() => {
const value = computedResult()
console.log('Updated at:', untrack(() => new Date().toISOString()))
})#Break circular dependencies
untrack breaks cycles where two signals depend on each other through effects:
createEffect(() => {
const a = signalA()
const b = untrack(() => signalB()) // Read B without tracking
setResult(a + b)
})