Widget events
Send events between widgets on the same dashboard from a Custom Metric widget — useWidgetEvents emitWidgetEvent, onWidgetEvent and onAnyWidgetEvent
Widgets on the same dashboard communicate through useWidgetEvents().
EMIT
emitWidgetEvent(event, payload) posts an event that other widgets can listen to.
GET (subscribe)
onWidgetEvent(event, cb)returns an unsubscribe function.onAnyWidgetEvent((event, payload) => …)returns an unsubscribe function.
How to implement: emit on click, listen on mount
import { useEffect } from 'react';
import { useWidgetEvents } from '@ubidots/react-html-canvas';
function Highlighter() {
const { emitWidgetEvent, onWidgetEvent } = useWidgetEvents();
useEffect(() => onWidgetEvent('highlight', (payload) => {
/* react to payload */
}), [onWidgetEvent]);
return <button onClick={() => emitWidgetEvent('highlight', { id: 1 })}>Ping</button>;
}Last updated
Was this helpful?