DocsBlog

Get Started

Components

Data Grid

Signals

Styling

Theming

↑↓Navigate
↵Select
EscClose
  • 1.8.0

  • Day

    Night

    Preview

    Switch mode
  • cerberus

    acheron

    elysium

    oceanus

Get Started
Components
Data Grid
Signals
Styling
Theming

Get started

OverviewReactivityData FetchingGlobal Stores

Primitives

Creating SignalsCreating QueriesCreating MutationsComputing Signal ValuesCreating EffectsContextual Signal StoresBatch UpdatesCleanup EffectsUntrack Signals

Hooks

Using QueriesUsing MutationsReading Primitive SignalsUsing SignalsUsing Store Instances

Components

Reactive Text

Untrack Signals

Learn how to read signals without subscribing to updates.

  • source
View as Markdown
Open this page in Markdown
Anthropic
Open in Claude
Ask questions about this page
OpenAI
Open in ChatGPT
Ask questions about this page
import { untrack } from '@cerberus/signals'

Usage

The untrack primitive allows you to read the current value of a signal inside a reactive context (like createEffect, createComputed, or a React render phase) without subscribing to that signal.

This prevents unwanted re-evaluations, React infinite loops, and over-subscribing to state changes.

In this example, we update a signal and show the latest result (tracked) and what the untracked version is.

Loading example...

When to use

By default, any signal read inside a tracking context will automatically bind to it. When that signal updates, the context re-runs. However, there are common scenarios where you only want to read the data, not react to it:

  1. Logging or Analytics: You want to fire an analytics event when userSignal changes, but you need to include the themeSignal value in the payload without re-firing the event when the theme changes.
  2. Preventing Infinite Loops: You need to conditionally initialize or mutate state based on the current value of a cache, without accidentally subscribing the surrounding component to the cache's internal lifecycle.
  3. Optimizing Component Renders: In React integrations, bypassing unnecessary subscriptions keeps your component from re-rendering O(1) updates that don't affect the DOM.

Best Practices

  • Keep it synchronous: untrack only disables tracking for the synchronous execution of the callback. If you use await inside the callback, signals read after the await might resume tracking depending on the environment context.
  • Keep it targeted: Wrap only the specific signal reads you want to isolate. Wrapping entire large blocks of logic can lead to accidentally missing subscriptions you actually intended to track.

API

untrack accepts an Accessor signal and returns the unsubscribed value at the time of calling.

On this page

  • Usage
  • When to use
  • Best Practices
  • API
Edit this page on Github

Count: 0

Untracked: 0

Render Count: 0