LangChain Reference home pageLangChain ReferenceLangChain Reference
  • GitHub
  • Main Docs
Deep Agents
LangChain
LangGraph
Integrations
LangSmith
  • Overview
  • Getting started
  • useStream
  • Selectors
  • Interrupts & headless tools
  • Subagents & subgraphs
  • Fork & edit from a checkpoint
  • Submission queue
  • Multimodal media
  • Transports
  • Suspense
  • StreamProvider & context
  • Type safety
  • Migrating to v1
LangGraph SDK
  • Client
  • Auth
  • React
  • Logging
  • React Ui
  • Server
LangGraph Checkpoint
LangGraph Checkpoint MongoDB
LangGraph Checkpoint Postgres
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

OverviewGetting starteduseStreamSelectorsInterrupts & headless toolsSubagents & subgraphsFork & edit from a checkpointSubmission queueMultimodal mediaTransportsSuspenseStreamProvider & contextType safetyMigrating to v1
LangGraph SDK
ClientAuthReactLoggingReact UiServer
LangGraph Checkpoint
LangGraph Checkpoint MongoDB
LangGraph Checkpoint Postgres
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/reactuseChannelEffect
Function●Since v1.0

useChannelEffect

Side-effect counterpart to useChannel. Instead of returning a buffer of events that re-renders the component, it invokes onEvent once per event for as long as the hook is mounted — the idiomatic place for analytics, logging, and other fire-and-forget side effects.

useChannelEffect(stream, ["lifecycle", "tools"], {
  replay: false,
  onEvent(event) {
    sendAnalytics(event);
  },
  onError(error) {
    logger.error(error);
  },
});

Notes:

  • onEvent / onError are read from a ref, so passing a fresh closure each render is fine — it never re-subscribes.
  • The underlying subscription is shared (ref-counted) with any matching useChannel consumer, so you only ever pay for one server subscription per channel set.
  • replay defaults to false (live-only). Set it to true only if you genuinely want to (re)process replayed history.
  • Events buffered before the hook mounts are not re-delivered.
Copy
useChannelEffect(
  stream: AnyStream,
  channels: readonly Channel[],
  options: UseChannelEffectOptions
)

Parameters

NameTypeDescription
stream*AnyStream
channels*readonly Channel[]
options*UseChannelEffectOptions
View source on GitHub