useChannelEffect(
stream: AnyStream,
channels: readonly Channel[],
options: UseChannelEffectOptions
)| Name | Type | Description |
|---|---|---|
stream* | AnyStream | |
channels* | readonly Channel[] | |
options* | UseChannelEffectOptions |
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.replay defaults to false (live-only). Set it to true only if
you genuinely want to (re)process replayed history.