useDashboardEventDispatch
Dispatch built-in or custom dashboard events from a plugin component with the alpha useDashboardEventDispatch hook.
useDashboardEventDispatch returns a function that sends a built-in or custom event to the dashboard event bus from a plugin component.
useDashboardEventDispatch is @alpha and may change. For a public alternative, dispatch the @beta triggerEvent
command through the public useDispatchDashboardCommand hook:
useDispatchDashboardCommand(triggerEvent).Basic usage
import { useDashboardEventDispatch } from "@gooddata/sdk-ui-dashboard";
export const NotifyButton = () => {
const dispatchEvent = useDashboardEventDispatch();
return (
<button onClick={() => dispatchEvent({ type: "CUSTOM/EVT/MY_WIDGET_CLICKED", payload: { source: "notify" } })}>
Notify
</button>
);
};
Handle the event like any other, for example with a custom event handler in a plugin; see Handle dashboard events.
Return value
(eventBody: DashboardEventBody<DashboardEvents | ICustomDashboardEvent>) => void: a function that wraps the event in the triggerEvent command and dispatches it. DashboardEventBody is the event without its ctx; the dashboard adds the context.
Notes
- The event
typemust start withGDC.DASH/EVT(a built-in event) orCUSTOM/EVT(a custom event). Any other value fails an invariant: “Unsupported event passed to useDashboardEventDispatch result.” - Call the hook inside a component rendered by the
Dashboardcomponent.
Related
Register typed handlers for Dashboard component events, read state and dispatch commands from a handler, and match commands to events.
Get the dispatch function of the dashboard store with the alpha useDashboardDispatch hook, or use the public useDispatchDashboardCommand.
Embed a saved dashboard with Dashboard, read its state through selectors, dispatch commands, handle events, configure behavior, and access its store externally.