---
url: /reference/items/Action.md
---
# Action
The `Action` component triggers declarative behavior on other components or DOM elements.
## Usage
This component can be directly imported and defined as a dependency of your application and then used directly with `data-...` attributes in your HTML.
In the following example, the buttons each have an `Action` component targeting the [`Transition`](/reference/items/Transition/index.html) component in the page.
:::code-group
```js
import { registerComponent } from '@studiometa/js-toolkit';
import { Action, Transition } from '@studiometa/ui';
registerComponent(Action);
registerComponent(Transition);
```
:::
The `Action` components can control multiple targets:
:::code-group
```js
import { registerComponent } from '@studiometa/js-toolkit';
import { Action, Transition } from '@studiometa/ui';
registerComponent(Action);
registerComponent(Transition);
```
:::
And specify an additional selector to filter the targeted components:
:::code-group
```js
import { registerComponent } from '@studiometa/js-toolkit';
import { Action, Transition } from '@studiometa/ui';
registerComponent(Action);
registerComponent(Transition);
```
:::
### Simple usage with the `Target` component
The `Target` component is a companion of the `Action` component that can be used to easily target other DOM elements without creating specific component.
:::code-group
```js
import { registerComponent } from '@studiometa/js-toolkit';
import { Action, Target } from '@studiometa/ui';
registerComponent(Action);
registerComponent(Target);
```
:::
### Combining it with `Data` components
:::code-group
```js
import { registerComponent } from '@studiometa/js-toolkit';
import { Action, DataBind, DataComputed } from '@studiometa/ui';
registerComponent(Action);
registerComponent(DataBind);
registerComponent(DataComputed);
```
:::
### Running an action on mount
The reserved [`mounted`](./js-api.md#reserved-events) event runs the effect once, when the DOM has settled after the action mounts. It lets HTML drive an initial call without every component gaining its own option for it.
:::code-group
```js
import { registerComponents } from '@studiometa/js-toolkit';
import { Action, Transition } from '@studiometa/ui';
registerComponents(Action, Transition);
```
:::
### Listening to multiple events
The advanced HTML [option `on:[.]`](./js-api.md#on-event-modifier) can be used to listen to multiple events on a single `Action` component.
:::code-group
```js
import { registerComponent } from '@studiometa/js-toolkit';
import { Action, Transition } from '@studiometa/ui';
registerComponent(Action);
registerComponent(Transition);
```
:::