useDashboardDispatch
Get the dispatch function of the dashboard store with the alpha useDashboardDispatch hook, or use the public useDispatchDashboardCommand.
useDashboardDispatch returns the Redux dispatch function of the dashboard store, so a plugin component can dispatch any dashboard command.
useDashboardDispatch is @alpha and may change. To dispatch a command, prefer the public
useDispatchDashboardCommand hook.Basic usage
import { changeFilterContextSelectionByParams, useDashboardDispatch } from "@gooddata/sdk-ui-dashboard";
export const ClearFiltersButton = () => {
const dispatch = useDashboardDispatch();
return (
<button onClick={() => dispatch(changeFilterContextSelectionByParams({ filters: [], resetOthers: true }))}>
Clear filters
</button>
);
};
The same with the public hook:
import { changeFilterContextSelectionByParams, useDispatchDashboardCommand } from "@gooddata/sdk-ui-dashboard";
export const ClearFiltersButton = () => {
const changeFilters = useDispatchDashboardCommand(changeFilterContextSelectionByParams);
return <button onClick={() => changeFilters({ filters: [], resetOthers: true })}>Clear filters</button>;
};
Return value
Dispatch<Action>: the Redux dispatch function of the dashboard store. Pass it a command object created by a command creator, such as changeFilterContextSelectionByParams(...).
Notes
- Call the hook inside a component rendered by the
Dashboardcomponent, for example a custom widget of a plugin. Outside of the dashboard store there is no store to dispatch to. useDispatchDashboardCommand(commandCreator)returns a function that takes the creator’s arguments and dispatches the command. Use it unless you need to dispatch several kinds of commands through one function.- For every command you can dispatch, see All commands. For the events the dashboard emits in response, see All events.
Related
Embed a saved dashboard with Dashboard, read its state through selectors, dispatch commands, handle events, configure behavior, and access its store externally.
Read Dashboard component state with useDashboardSelector and the select* selectors, from components, event handlers, and outside code.
Dispatch built-in or custom dashboard events from a plugin component with the alpha useDashboardEventDispatch hook.
Register typed handlers for Dashboard component events, read state and dispatch commands from a handler, and match commands to events.