Skip to content

untracked

Read signals without tracking dependencies.

/**
* Execute a function without tracking signal dependencies.
* @param callback Function to execute untracked.
* @returns The result of the function.
*/
untracked<T>(callback: () => T): T

Use untracked to read a signal inside an effect or computed without creating a dependency. This prevents the parent effect or computed from re-running when the signal changes.

import { signal, effect, untracked } from '@hellajs/core';
const count = signal(0);
const threshold = signal(10);
effect(() => {
// This creates a dependency on count
const currentCount = count();
// This does NOT create a dependency on threshold
const currentThreshold = untracked(() => threshold());
console.log(`Count: ${currentCount}, Threshold: ${currentThreshold}`);
});
// Effect runs, logs: "Count: 0, Threshold: 10"
count.set(1);
// Effect runs, logs: "Count: 1, Threshold: 10"
threshold.set(20);
// Effect doesn't run, since threshold was read via untracked