[]previous and next page

currentListener

Returns the computation that records reads right now.

Returns the computation that records reads right now. Use it in a primitive whose read behaves differently for a tracked reader, for example one that holds a boundary only for a listening memo or effect.

Import#

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

Signature#

ts
function currentListener(): Computation | null

Returns#

The listening memo or effect, or null when reads are untracked.

Examples#

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

function readWithStats<T>(read: () => T, stats: { tracked: number }): T {
  if (currentListener() !== null) stats.tracked += 1;
  return read();
}