useChannelEffect(
stream: AnyStream,
channels: ValueOrGetter<readonly Channel[]>,
options: UseChannelEffectOptions
)| Name | Type | Description |
|---|---|---|
stream* | AnyStream | |
channels* | ValueOrGetter<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.
<script lang="ts">
useChannelEffect(stream, ["lifecycle", "tools"], {
replay: false,
onEvent(event) {
sendAnalytics(event);
},
onError(error) {
logger.error(error);
},
});
</script>
Reactive channels / target / enabled getters 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 reactive context (a .svelte component script
or inside $effect.root).