Skip to content

React Integration

lostcause edited this page Aug 24, 2026 · 1 revision

React integration

@0xx0lostcause0xx0/polypack/react provides hooks over a PolyGraph. React is an optional peer dependency, only loaded from this subpath. React 18 and 19 are supported.

useGraphQuery(graph, queryFn, deps, delay?, nodeTypes?, onError?)
useLiveQuery(graph, querier, deps?, defaultResult?)

Both hooks execute immediately, subscribe to graph changes, and support sync or async queries:

  • useGraphQuery defaults to a 200ms debounce. When nodeTypes is supplied, change events for other known node types are ignored. Query errors are logged, passed to the optional onError(error) callback, and set the result to undefined.
  • The dependency list controls query closure refresh the same way it does for other React hooks. Changing nodeTypes or delay updates the active subscription without requiring dependency-list changes. In-flight queries are serialized; stale results are discarded after dependency changes or unmounting, and one follow-up run is retained when mutations arrive during an asynchronous query.

Working memory

useWorkingMemory(graph, limit?, deps?, delay?, nodeTypes?, engine?)

A live view of the current working memory: the limit most-activated loaded nodes, re-queried after any graph change (including activation_updated).

  • deps controls re-runs and must include limit when it can change.
  • Without engine, it ranks by graph.topActivated (durable score only).
  • Pass an ActivationEngine to rank by engine.workingMemory instead (durable score plus transient attention from bumpAttention).
  • Sub-threshold bumpAttention calls never emit a graph change event, so they won't trigger an automatic re-run on their own — include something that changes after a bump in deps if the view needs to reflect it immediately.

Back to Home.

Clone this wiki locally