• Subscribe to a slice of the graph.

    Type Parameters

    • T

      The selector's return type.

    Parameters

    • selector: Selector<T>

      Pure projection from the current Graph to the value the component cares about.

    Returns T

    The currently-selected value; changes between renders only when the selector returns a value not Object.is-equal to the previous return.

    Error when called outside <CauslProvider>.

    Backed by useSyncExternalStore so React 18 concurrent rendering and strict-mode double-invocation behave correctly. The subscription is to the graph's commit log — the engine exposes the transaction log as a Behavior [Commit] queryable through the same primitives as any other graph value, and subscribeCommits is the narrow notification capability built on top of it. Every commit is a candidate for re-evaluation; the Object.is dedup at the selector boundary prevents unrelated commits from causing a render.

    For selectors returning fresh objects or arrays per call, prefer useCauslShallow so structurally-equal returns do not defeat the dedup. A fresh-object selector used here is safe from the classic 'Maximum update depth exceeded' loop — the snapshot is pinned per GraphTime, so with zero intervening commits the retained reference is returned rather than a new one (#154) — but every commit still re-renders because Object.is cannot see that the contents are unchanged. In development that situation logs an unstable-snapshot warning naming useCauslShallow as the fix.

    const sum = useCausl((g) => g.read(sumNode))