Read signals without creating dependencies. Perfect for optimization and preventing unnecessary updates!
untrack() to read signals without tracking themCompute both results, then change each signal to see the difference!
const result = count + dependency;
// Re-computes when EITHER changesBoth signals are tracked as dependencies
const result = count + untrack(() => dependency);
// Only re-computes when count changes!Only count is tracked; dependency is ignored
import { createSignal, createComputed, untrack } from 'signalforge/core';
const currentUser = createSignal({ id: 1, name: 'Alice' });
const theme = createSignal('dark');
// BAD: Re-computes when theme changes (unnecessary!)
const userDisplayBad = createComputed(() => {
const user = currentUser.get();
const themeColor = theme.get(); // Tracked!
return `${user.name} (theme: ${themeColor})`;
});
// GOOD: Only re-computes when user changes
const userDisplayGood = createComputed(() => {
const user = currentUser.get();
const themeColor = untrack(() => theme.get()); // NOT tracked!
return `${user.name} (theme: ${themeColor})`;
});
// Now changing theme won't trigger userDisplayGood!
theme.set('light'); // userDisplayBad updates ❌
// userDisplayGood stays same ✅const display = computed(() => {
const data = mainData.get();
const theme = untrack(() => uiTheme.get());
return formatData(data, theme);
});const stats = computed(() => {
const data = dataset.get();
const precision = untrack(() => decimals.get());
return calculateStats(data).toFixed(precision);
});const canEdit = computed(() => {
const post = currentPost.get();
const userId = untrack(() => user.get().id);
return post.authorId === userId;
});const log = computed(() => {
const message = logMessage.get();
const t = untrack(() => currentTime.get());
return `[${t}] ${message}`;
});When you need a value but don't want to recompute when it changes.
Only use when you have a specific performance reason. Most signals should be tracked!
Theme, locale, display settings - things that don't affect data calculations.
Read a signal once without tracking future changes.
Using untrack() can significantly improve performance when you have:
Master untrack? Try these advanced demos: