Skip to main content
πŸ‘€ Interested in the latest enterprise backend features of refine? πŸ‘‰ Join now and get early access!
Version: 4.xx.xx
Source Code

useSubscription

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

INFORMATION

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​

useSubscription will be passed to the subscribe method from the liveProvider as a parameter. You can use the following properties of this method while subcribing to a channel.

channel
required
​

Channel name to subscribe to.

onLiveEvent
required
​

Callback that is run when new events from the subscription arrive.

types​

Default: ["*"]

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

enabled​

Default: true

You can disable the subscription by setting this prop to false and vice versa.

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.

For more information on which hooks use useSubcription internally, refer to the LiveProvider's "Supported Hooks Subscription" section→

API Reference​

Properties​