Skip to main content
Version: 4.xx.xxSource Code

useSubscription

useSubscription calls the subscribe method from liveProvider when mounted. It is useful when you want to subscribe to a Realtime channel.

info

refine use this hook internally in data hooks to subscribe Realtime data. You can refer liveProvider's Supported Hooks Subscriptions section for more information.

Usage​

import { useSubscription } from "@refinedev/core";

useSubscription({
channel: "channel-name",
types: ["event-name", "another-event-name"]
onLiveEvent: (event) => {},
});

Properties​

Will be passed to the subscribe method from the liveProvider as a parameter. You can use these properties from the liveProvider's subscribe method and use them to subscribe to a channel.

channel
required
​

Channel name to subscribe.

onLiveEvent
required
​

Callback that is run when new events from subscription arrive.

types​

Default: ["*"]

Type of events to subscribe. "\*" means all events.

enabled​

Default: true

params​

You can pass any additional parameters to the liveProvider's subscribe method.

Hooks that use useSubscription internally, send the query's parameters(pagination, meta, sort, filters, etc.) information along with this prop.

Refer to LiveProvider's "Supported Hooks Subscription" section for which hooks are using useSubscription internally β†’

API Reference​

Properties​