> Documentation index: https://www.gooddata.ai/docs/gooddata-ui/llms.txt lists every page of these docs as Markdown.

# useDashboardDispatch

> Get the dispatch function of the dashboard store with the alpha useDashboardDispatch hook, or use the public useDispatchDashboardCommand.

API reference: [useDashboardDispatch()](https://www.gooddata.ai/docs/gooddata-ui/latest/api-reference/sdk-ui-dashboard/sdk-ui-dashboard.usedashboarddispatch/index.md) (function, alpha)

`useDashboardDispatch` returns the Redux `dispatch` function of the dashboard store, so a plugin component can dispatch any dashboard command.

> **Alpha API:**
> `useDashboardDispatch` is `@alpha` and may change. To dispatch a command, prefer the public
> [`useDispatchDashboardCommand`](https://www.gooddata.ai/docs/gooddata-ui/latest/dashboard-plugins/dashboard/index.md#commands) hook.

## [Basic usage](https://www.gooddata.ai/docs/gooddata-ui/latest/dashboard-plugins/use-dashboard-dispatch/#basic-usage)

```tsx
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:

```tsx
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](https://www.gooddata.ai/docs/gooddata-ui/latest/dashboard-plugins/use-dashboard-dispatch/#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](https://www.gooddata.ai/docs/gooddata-ui/latest/dashboard-plugins/use-dashboard-dispatch/#notes)

- Call the hook inside a component rendered by the [`Dashboard`](https://www.gooddata.ai/docs/gooddata-ui/latest/api-reference/sdk-ui-dashboard/sdk-ui-dashboard.dashboard/index.md) component, 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](https://www.gooddata.ai/docs/gooddata-ui/latest/dashboard-plugins/dashboard/index.md#all-commands). For the events the dashboard emits in response, see [All events](https://www.gooddata.ai/docs/gooddata-ui/latest/dashboard-plugins/dashboard-events/index.md#all-events).
