# DatAInsights Composer Events

The KendoReact DatAInsights Composer raises events for the prompt, the generated visualizations, the History, and its lifecycle state. The events notify your app about what happened. None of them is cancelable, and only [`onDataProcess`](https://www.telerik.com/kendo-react-ui-develop/components/datainsights-composer/api/datainsightscomposerprops#ondataprocess) uses the value that you return from the handler.

The following list describes when each event fires. For the arguments of each event, see the [API reference](https://www.telerik.com/kendo-react-ui-develop/components/datainsights-composer/api/datainsightscomposerprops).

## Prompt and Generation

* [`onPromptChange`](https://www.telerik.com/kendo-react-ui-develop/components/datainsights-composer/api/datainsightscomposerprops#onpromptchange)—Fires on every keystroke in the prompt or in the refine prompt.
* [`onPromptSubmit`](https://www.telerik.com/kendo-react-ui-develop/components/datainsights-composer/api/datainsightscomposerprops#onpromptsubmit)—Fires on every prompt submission, including refinements. Without an `aiClient`, handle it to [run the request yourself](https://www.telerik.com/kendo-react-ui-develop/components/datainsights-composer/controlled-mode#controlled-with-your-own-request-handling).
* [`onPromptCancel`](https://www.telerik.com/kendo-react-ui-develop/components/datainsights-composer/api/datainsightscomposerprops#onpromptcancel)—Fires when a pending request is abandoned, for example, when the user clicks **Stop**.
* [`onStateChange`](https://www.telerik.com/kendo-react-ui-develop/components/datainsights-composer/api/datainsightscomposerprops#onstatechange)—Fires after every [state](https://www.telerik.com/kendo-react-ui-develop/components/datainsights-composer/states-and-messages) transition.
* [`onError`](https://www.telerik.com/kendo-react-ui-develop/components/datainsights-composer/api/datainsightscomposerprops#onerror)—Fires when an AI client call or the data processing fails, or when a visualization cannot be rendered. A request that the AI declines is not an error.

## Datasets and Data

* [`onDatasetResolve`](https://www.telerik.com/kendo-react-ui-develop/components/datainsights-composer/api/datainsightscomposerprops#ondatasetresolve)—Fires when the AI selects a dataset and the component has no active one. See [multiple datasets](https://www.telerik.com/kendo-react-ui-develop/components/datainsights-composer/data-binding#multiple-datasets).
* [`onDataProcess`](https://www.telerik.com/kendo-react-ui-develop/components/datainsights-composer/api/datainsightscomposerprops#ondataprocess)—Fires when the data of the visualization is available and when the configuration or the data changes. Return the rows to display, or `undefined` to keep the built-in processing.

## Visualizations

* [`onConfigChange`](https://www.telerik.com/kendo-react-ui-develop/components/datainsights-composer/api/datainsightscomposerprops#onconfigchange)—Fires whenever the component produces a valid set of configurations. In controlled mode, pass the new values back through the `configs` property.
* [`onEditingChange`](https://www.telerik.com/kendo-react-ui-develop/components/datainsights-composer/api/datainsightscomposerprops#oneditingchange)—Fires when the component opens or closes the edit mode.
* [`onConfirm`](https://www.telerik.com/kendo-react-ui-develop/components/datainsights-composer/api/datainsightscomposerprops#onconfirm)—Fires when the user clicks **Confirm**. Use it to [persist the visualization](https://www.telerik.com/kendo-react-ui-develop/components/datainsights-composer/editing#persisting-and-restoring-visualizations).
* [`onDiscard`](https://www.telerik.com/kendo-react-ui-develop/components/datainsights-composer/api/datainsightscomposerprops#ondiscard)—Fires when the user clicks **Discard** and the component restores the configurations from the start of the edit mode. If the restored configurations differ from the displayed ones, `onConfigChange` also fires with the `discard` origin.
* [`onRemove`](https://www.telerik.com/kendo-react-ui-develop/components/datainsights-composer/api/datainsightscomposerprops#onremove)—Fires when the user clicks **Remove**. `onConfigChange` fires after it with the `remove` origin and empty values. When `configs` is controlled, clear them in the handler.

## History

* [`onHistoryItemCreate`](https://www.telerik.com/kendo-react-ui-develop/components/datainsights-composer/api/datainsightscomposerprops#onhistoryitemcreate)—Fires after a successful generation or refinement adds a History item.
* [`onHistoryItemRestore`](https://www.telerik.com/kendo-react-ui-develop/components/datainsights-composer/api/datainsightscomposerprops#onhistoryitemrestore)—Fires when the user restores a History item.

The following example handles the component events and logs them. It starts with a Column chart of the total revenue by region. Refine the visualization, restore a History item, and confirm or discard the changes to see the order in which the events fire. To see `onDatasetResolve`, confirm the changes, click **Remove**, and submit a new prompt, because the example has two datasets and no active one after the removal.

[Demo Source](https://demos.telerik.com/kendo-react-ui/datainsights-composer/events/source.txt)

## Suggested Links

* [DatAInsights Composer Overview](https://www.telerik.com/kendo-react-ui-develop/components/datainsights-composer)
* [DatAInsights Composer Controlled Mode](https://www.telerik.com/kendo-react-ui-develop/components/datainsights-composer/controlled-mode)
* [DatAInsights Composer States and Messages](https://www.telerik.com/kendo-react-ui-develop/components/datainsights-composer/states-and-messages)
* [Getting Started with the KendoReact DatAInsights Composer](https://www.telerik.com/kendo-react-ui-develop/components/datainsights-composer/get-started)
* [API Reference of the DatAInsights Composer](https://www.telerik.com/kendo-react-ui-develop/components/datainsights-composer/api)
