Skip to main content
Version: 3.xx.xx
Source Code

usePublish

usePublish returns the publish method from liveProvider. It is useful when you want to publish a custom event.

INFORMATION

refine use this hook internally in mutation hooks to publish events after successful mutation. You can refer liveProvider's Publish Events from Hooks section for more information.

Usage

import { usePublish } from "@pankod/refine-core";

const publish = usePublish();

publish({
channel: "custom-channel-name",
type: "custom-event-name",
payload: {
ids: [1, 2, 3],
"custom-property": "custom-property-value",
},
date: new Date(),
});
CAUTION

This method is used to publish an event on the client side. Beware that publishing events on the client side is not recommended and the best practice is to publish events from the server side. You can refer Publish Events from API to see which events must be published from the server.

Publish Properties

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

Refer to LiveEvent interface for type of properties.

channel
required

The channel name to publish the event.

type
required

The event name to publish.

payload
required

The payload to publish.

date
required

The date of the event.