Skip to content

untracked

/**
* @param fn The function to execute without tracking signal dependencies
* @returns The result of the function execution
*/
untracked<T>(fn: () => T): T

Allows you to access signal values without creating dependencies. It’s useful when you need to read a signal’s value within an effect or computed value without causing that effect to re-run when the signal changes.

import { signal, effect, untracked } from '@hellajs/core';
const count = signal(0);
const threshold = signal(10);
effect(() => {
// This will create a dependency on count
const currentCount = count();
// This will 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
import { signal, computed, untracked } from '@hellajs/core';
const items = signal([1, 2, 3, 4]);
const config = signal({ shouldFilter: true, threshold: 3 });
const filteredItems = computed(() => {
const list = items();
// Only track config.shouldFilter, not the whole config object
const shouldFilter = config().shouldFilter;
if (shouldFilter) {
// Don't track threshold changes
const threshold = untracked(() => config().threshold);
return list.filter(item => item <= threshold);
}
return list;
});