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

# IDashboardEventHandling

- Package: [@gooddata/sdk-ui-dashboard](https://www.gooddata.ai/docs/gooddata-ui/latest/api-reference/sdk-ui-dashboard/index.md)
- Kind: interface
- Source: https://github.com/gooddata/gooddata-ui-sdk/blob/rel/11.64/libs/sdk-ui-dashboard/src/plugins/customizer.ts
- Guides: [Handle dashboard events](https://www.gooddata.ai/docs/gooddata-ui/latest/dashboard-plugins/dashboard-events/index.md)

Defines a facade that you can use to register or unregister dashboard event handlers.

**Signature:**

```typescript
export interface IDashboardEventHandling 
```

## Methods

| Method | Description |
| --- | --- |
| [addCustomEventHandler(handler)](https://www.gooddata.ai/docs/gooddata-ui/latest/api-reference/sdk-ui-dashboard/sdk-ui-dashboard.idashboardeventhandling/index.md#idashboardeventhandlingaddcustomeventhandler) | Adds a custom event handler. This is a lower-level API where the handler can include both the function to evaluate events and the function to trigger when the evaluation succeeds. |
| [addEventHandler(eventType, callback)](https://www.gooddata.ai/docs/gooddata-ui/latest/api-reference/sdk-ui-dashboard/sdk-ui-dashboard.idashboardeventhandling/index.md#idashboardeventhandlingaddeventhandler) | Adds a handler for particular event type. |
| [removeCustomEventHandler(handler)](https://www.gooddata.ai/docs/gooddata-ui/latest/api-reference/sdk-ui-dashboard/sdk-ui-dashboard.idashboardeventhandling/index.md#idashboardeventhandlingremovecustomeventhandler) | Removes custom event handler. |
| [removeEventHandler(eventType, callback)](https://www.gooddata.ai/docs/gooddata-ui/latest/api-reference/sdk-ui-dashboard/sdk-ui-dashboard.idashboardeventhandling/index.md#idashboardeventhandlingremoveeventhandler) | Removes a handler for particular event type. This is reverse operation to [IDashboardEventHandling.addEventHandler()](https://www.gooddata.ai/docs/gooddata-ui/latest/api-reference/sdk-ui-dashboard/sdk-ui-dashboard.idashboardeventhandling/index.md#idashboardeventhandlingaddeventhandler). |
| [subscribeToStateChanges(callback)](https://www.gooddata.ai/docs/gooddata-ui/latest/api-reference/sdk-ui-dashboard/sdk-ui-dashboard.idashboardeventhandling/index.md#idashboardeventhandlingsubscribetostatechanges) | Subscribe to state changes of the dashboard. |
| [unsubscribeFromStateChanges(callback)](https://www.gooddata.ai/docs/gooddata-ui/latest/api-reference/sdk-ui-dashboard/sdk-ui-dashboard.idashboardeventhandling/index.md#idashboardeventhandlingunsubscribefromstatechanges) | Unsubscribe from receiving calls about state changes of the dashboard. |

## Method details

### IDashboardEventHandling.addCustomEventHandler()

Adds a custom event handler. This is a lower-level API where the handler can include both the function to evaluate events and the function to trigger when the evaluation succeeds.

**Signature:**

```typescript
addCustomEventHandler(handler: DashboardEventHandler): IDashboardEventHandling;
```

#### Parameters

| Parameter | Type | Description |
| --- | --- | --- |
| handler | [DashboardEventHandler](https://www.gooddata.ai/docs/gooddata-ui/latest/api-reference/sdk-ui-dashboard/sdk-ui-dashboard.dashboardeventhandler/index.md) | event handler to add |

**Returns:**

[IDashboardEventHandling](https://www.gooddata.ai/docs/gooddata-ui/latest/api-reference/sdk-ui-dashboard/sdk-ui-dashboard.idashboardeventhandling/index.md)

self, for call chaining sakes

#### Remarks

Attempts to register same handler twice will be ignored.

### IDashboardEventHandling.addEventHandler()

Adds a handler for particular event type.

**Signature:**

```typescript
addEventHandler<TEvents extends DashboardEvents | ICustomDashboardEvent>(eventType: string, callback: DashboardEventHandlerFn<TEvents>): IDashboardEventHandling;
```

#### Parameters

| Parameter | Type | Description |
| --- | --- | --- |
| eventType | string | type of the event to handle; this can be either built-event event type (see [DashboardEventType](https://www.gooddata.ai/docs/gooddata-ui/latest/api-reference/sdk-ui-dashboard/sdk-ui-dashboard.dashboardeventtype/index.md)), a custom event type or `'*'` to register handler for all events |
| callback | [DashboardEventHandlerFn](https://www.gooddata.ai/docs/gooddata-ui/latest/api-reference/sdk-ui-dashboard/sdk-ui-dashboard.dashboardeventhandlerfn/index.md)&lt;TEvents&gt; | function to call when the event occurs |

**Returns:**

[IDashboardEventHandling](https://www.gooddata.ai/docs/gooddata-ui/latest/api-reference/sdk-ui-dashboard/sdk-ui-dashboard.idashboardeventhandling/index.md)

#### Remarks

Every time event of that type occurs, the provided callback function will be triggered.

### IDashboardEventHandling.removeCustomEventHandler()

Removes custom event handler.

**Signature:**

```typescript
removeCustomEventHandler(handler: DashboardEventHandler): IDashboardEventHandling;
```

#### Parameters

| Parameter | Type | Description |
| --- | --- | --- |
| handler | [DashboardEventHandler](https://www.gooddata.ai/docs/gooddata-ui/latest/api-reference/sdk-ui-dashboard/sdk-ui-dashboard.dashboardeventhandler/index.md) | event handler to remove |

**Returns:**

[IDashboardEventHandling](https://www.gooddata.ai/docs/gooddata-ui/latest/api-reference/sdk-ui-dashboard/sdk-ui-dashboard.idashboardeventhandling/index.md)

self, for call chaining sakes

#### Remarks

In order for successful removal the entire handler object must be exactly the same as the one that was used when you added the handler.

### IDashboardEventHandling.removeEventHandler()

Removes a handler for particular event type. This is reverse operation to [IDashboardEventHandling.addEventHandler()](https://www.gooddata.ai/docs/gooddata-ui/latest/api-reference/sdk-ui-dashboard/sdk-ui-dashboard.idashboardeventhandling/index.md#idashboardeventhandlingaddeventhandler).

**Signature:**

```typescript
removeEventHandler<TEvents extends DashboardEvents | ICustomDashboardEvent>(eventType: string, callback: DashboardEventHandlerFn<TEvents>): IDashboardEventHandling;
```

#### Parameters

| Parameter | Type | Description |
| --- | --- | --- |
| eventType | string | type of the event to stop handling; this can be either built-event event type (see [DashboardEventType](https://www.gooddata.ai/docs/gooddata-ui/latest/api-reference/sdk-ui-dashboard/sdk-ui-dashboard.dashboardeventtype/index.md)), a custom event type or `'*'` to register handler for all events |
| callback | [DashboardEventHandlerFn](https://www.gooddata.ai/docs/gooddata-ui/latest/api-reference/sdk-ui-dashboard/sdk-ui-dashboard.dashboardeventhandlerfn/index.md)&lt;TEvents&gt; | originally registered callback function |

**Returns:**

[IDashboardEventHandling](https://www.gooddata.ai/docs/gooddata-ui/latest/api-reference/sdk-ui-dashboard/sdk-ui-dashboard.idashboardeventhandling/index.md)

self, for call chaining sakes

#### Remarks

In order for this method to remove a handler, the arguments must be the same when you added the handler.

E.g. it is not possible to add a handler for all events using `'*'` and then subtract just one particular event from handling.

### IDashboardEventHandling.subscribeToStateChanges()

Subscribe to state changes of the dashboard.

**Signature:**

```typescript
subscribeToStateChanges(callback: DashboardStateChangeCallback): IDashboardEventHandling;
```

#### Parameters

| Parameter | Type | Description |
| --- | --- | --- |
| callback | [DashboardStateChangeCallback](https://www.gooddata.ai/docs/gooddata-ui/latest/api-reference/sdk-ui-dashboard/sdk-ui-dashboard.dashboardstatechangecallback/index.md) | function to call when dashboard state changes; the function will be called with two parameters: the new state and an instance of dispatch to use. |

**Returns:**

[IDashboardEventHandling](https://www.gooddata.ai/docs/gooddata-ui/latest/api-reference/sdk-ui-dashboard/sdk-ui-dashboard.idashboardeventhandling/index.md)

self, for call chaining sakes

#### Remarks

There is no need to use this if all you need is your custom React components to get up-to-date state. Your React component code can (and really should) use the [useDashboardSelector](https://www.gooddata.ai/docs/gooddata-ui/latest/api-reference/sdk-ui-dashboard/sdk-ui-dashboard.usedashboardselector/index.md) and [useDashboardDispatch()](https://www.gooddata.ai/docs/gooddata-ui/latest/api-reference/sdk-ui-dashboard/sdk-ui-dashboard.usedashboarddispatch/index.md) hooks instead.

Subscription to state changes is only really needed if you have custom code outside of React components and you need to extract custom data from state using the selectors API.

See also [SingleDashboardStoreAccessor](https://www.gooddata.ai/docs/gooddata-ui/latest/api-reference/sdk-ui-dashboard/sdk-ui-dashboard.singledashboardstoreaccessor/index.md) and [DashboardStoreAccessorRepository](https://www.gooddata.ai/docs/gooddata-ui/latest/api-reference/sdk-ui-dashboard/sdk-ui-dashboard.dashboardstoreaccessorrepository/index.md) for utility classes that make managing the callback subscriptions more convenient.

### IDashboardEventHandling.unsubscribeFromStateChanges()

Unsubscribe from receiving calls about state changes of the dashboard.

**Signature:**

```typescript
unsubscribeFromStateChanges(callback: DashboardStateChangeCallback): IDashboardEventHandling;
```

#### Parameters

| Parameter | Type | Description |
| --- | --- | --- |
| callback | [DashboardStateChangeCallback](https://www.gooddata.ai/docs/gooddata-ui/latest/api-reference/sdk-ui-dashboard/sdk-ui-dashboard.dashboardstatechangecallback/index.md) | callback that was previously used for subscription |

**Returns:**

[IDashboardEventHandling](https://www.gooddata.ai/docs/gooddata-ui/latest/api-reference/sdk-ui-dashboard/sdk-ui-dashboard.idashboardeventhandling/index.md)

self, for call chaining sakes
