[]previous and next page

untrack

Runs fn without subscribing the running computation to anything fn reads.

Runs fn without subscribing the running computation to anything fn reads. Use it inside an effect or a memo to read a value without re-running when that value changes. The current owner is kept, so effects and cleanups created inside fn are still owned.

Import#

ts
import { untrack } from "@shadow-js/core";

Signature#

ts
function untrack<T>(fn: () => T): T

Parameters#

Name Description
fn The function to run untracked.

Returns#

Whatever fn returns. An error thrown by fn propagates unchanged.

Examples#

ts
import { untrack, useEffect, useSignal } from "@shadow-js/core";

const [count, setCount] = useSignal(0);
const [unit] = useSignal("clicks");
useEffect(() => {
  // Re-runs when `count` changes, never when `unit` changes.
  console.log(`${count()} ${untrack(unit)}`);
});
setCount(1);