> For the complete documentation index, see [llms.txt](https://docs.feathery.io/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.feathery.io/develop/react/api-guide/form/event-handlers/onaction.md).

# onAction()

### Overview

`onAction` is a [\<Feathery.Form>](/develop/react/api-guide/form.md) prop and callback function to access and modify form state when  [actions](/platform/build-forms/actions.md) attached to an element like a [button](/platform/build-forms/elements/basic/button.md) or [container](/platform/build-forms/elements/basic/container.md) are triggered, usually via a click. This handler will run twice, once before the element actions are run and once after the element actions are run.

Default form validation logic, if toggled, will run before either case. If an error is detected, `onAction` will not run until the field error is fixed and the element is clicked again. This function can be asynchronous.

### Usage <a href="#usage" id="usage"></a>

You can use `onAction` to short-circuit actions, render a custom component, set field values, and more. The function takes a single [Context](#context-api) object that provides form-related state and handlers.

```
import { init, Form } from '@feathery/react';

function App() {
  // Initialize Feathery
  init('SDKKey', 'bob@feathery.io');

  // Show the `aBcDeF` Feathery form
  return <Form
    formId='aBcDeF'
    // Route to a specific step
    onAction={(context) => {
      context.goToStep("Custom Step");
    }}
  />
}
```

### Context API

|                   Key                   |                Type                | Description                                                                        |
| :-------------------------------------: | :--------------------------------: | ---------------------------------------------------------------------------------- |
| [Form Context](/develop/context-api.md) |                                    | Consistently available form state and functions                                    |
|                `trigger`                | [triggerData](#triggerdata-object) | The info of the custom action trigger.                                             |
|               `actionData`              |             `Action[]`             | The [actions](/platform/build-forms/actions.md) being run                          |
|           `beforeClickActions`          |              `boolean`             | If `onAction` is running before the element click actions have been run, or after. |
|          Deprecated: `actions`          |             `string[]`             | The [actions](/platform/build-forms/actions.md) being run                          |

#### `triggerData` Definition <a href="#triggerdata-object" id="triggerdata-object"></a>

|      Key      |      Type     | Description                                                                                                                                                  |
| :-----------: | :-----------: | ------------------------------------------------------------------------------------------------------------------------------------------------------------ |
|      `id`     |    `string`   | The ID of the element that triggered the custom action                                                                                                       |
|     `text`    |    `string`   | The text displayed on the element that triggered the custom action.                                                                                          |
|     `type`    | `string enum` | The type of element that triggered the custom action. Can be `button`, `text`, or `field`.                                                                   |
| `repeatIndex` |   `integer`   | If the element that triggered the action repeats, this specifies which repetition it is. This value is 0-indexed and equals 0 if the element doesn't repeat. |

### Return value

A promise can be optionally returned from this function if it's asynchronous and you want execution to await.


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://docs.feathery.io/develop/react/api-guide/form/event-handlers/onaction.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
