LangChain Reference home pageLangChain ReferenceLangChain Reference
  • GitHub
  • Main Docs
Deep Agents
LangChain
LangGraph
Integrations
LangSmith
LangGraph
  • Web
  • Channels
  • Pregel
  • Prebuilt
  • Remote
React SDK
Vue SDK
Svelte SDK
Angular SDK
LangGraph SDK
  • Ui
  • Client
  • Auth
  • React
  • Logging
  • React Ui
  • Utils
  • Server
  • Stream
LangGraph Checkpoint
LangGraph Checkpoint MongoDB
LangGraph Checkpoint Postgres
  • Store
LangGraph Checkpoint Redis
  • Shallow
  • Store
LangGraph Checkpoint SQLite
LangGraph Checkpoint Validation
  • Cli
LangGraph API
LangGraph CLI
LangGraph CUA
  • Utils
LangGraph Supervisor
LangGraph Swarm
⌘I

LangChain Assistant

Ask a question to get started

Enter to send•Shift+Enter new line

Menu

LangGraph
WebChannelsPregelPrebuiltRemote
React SDK
Vue SDK
Svelte SDK
Angular SDK
LangGraph SDK
UiClientAuthReactLoggingReact UiUtilsServerStream
LangGraph Checkpoint
LangGraph Checkpoint MongoDB
LangGraph Checkpoint Postgres
Store
LangGraph Checkpoint Redis
ShallowStore
LangGraph Checkpoint SQLite
LangGraph Checkpoint Validation
Cli
LangGraph API
LangGraph CLI
LangGraph CUA
Utils
LangGraph Supervisor
LangGraph Swarm
Language
Theme
JavaScript@langchain/reactuseProjection
Function●Since v1.0

useProjection

Copy
useProjection<
  T
>(
  registry: ChannelRegistry | null | undefined,
  specFactory: () => ProjectionSpec
View source on GitHub
<
T
>
,
key
:
string
,
initialValue
:
T
)
:
T

Parameters

NameTypeDescription
registry*ChannelRegistry | null | undefined
specFactory*() => ProjectionSpec<T>
key*string
initialValue*T

React-side primitive that composes ChannelRegistry.acquire with useSyncExternalStore.

Contract:

  • On mount (or when key changes) this hook acquires a ref-counted projection from the registry and subscribes to its store. React re-renders automatically whenever the store's snapshot changes.
  • On unmount (or when key changes) the previous acquisition is released. If this was the last consumer of that spec, the registry closes the underlying server subscription.

The first render (before useEffect runs) returns initialValue. Subsequent renders read from the acquired store.

Framework bindings for Vue/Svelte/Angular follow the same shape — acquire on setup/mount, release on scope-dispose/unmount — but use their own reactivity primitive instead of useSyncExternalStore.