useChannelEffect(
stream: AnyStream,
channels: MaybeRefOrGetter<readonly Channel[]>,
options: UseChannelEffectOptions
)| Name | Type | Description |
|---|---|---|
stream* | AnyStream | |
channels* | MaybeRefOrGetter<readonly Channel[]> | |
options* | UseChannelEffectOptions |
Side-effect counterpart to useChannel. Instead of returning a
reactive buffer, it invokes onEvent once per event for as long as
the calling scope is alive — 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);
},
});
Reactive channels / target / enabled re-bind the subscription
when they change. The underlying subscription is shared (ref-counted)
with any matching useChannel consumer. replay defaults to
false (live-only); events buffered before the effect attaches are
not re-delivered.
Must be called from a component setup() (or another effect scope) so
the subscription is torn down on onScopeDispose.