# onChange()

### Overview

This is a [\<Feathery.Form>](/develop/react/api-guide/form.md) prop and callback function to run custom logic when a field value is changed. It's called every time the user changes one or multiple field values. This function can be asynchronous.

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

You can use `onChange` to log or update form state when the user modifies it. It 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'
    // Custom form step onChange logic
    onChange={(context) => {
      if (context.trigger.id === 'is-it-birthday' && context.fields['is-it-birthday']) {
          showBirthdaySurprise();
      }
    }}
  />
}
```

### Context API

|                   Key                   |                Type                | Description                                                                                                                                                                                                                               |
| :-------------------------------------: | :--------------------------------: | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| [Form Context](/develop/context-api.md) |                                    | Consistently available form state and functions                                                                                                                                                                                           |
|            `integrationData`            |          `optional object`         | Third-party metadata may be passed back through this property. If `trigger` equals `addressSelect`, this object returns the  Google Places address ID (`id`), the components of its address, and the latitude / longitude of the address. |
|                `trigger`                | [triggerData](#triggerdata-object) | Info of the element that triggered the field value change.                                                                                                                                                                                |
|            `valueRepeatIndex`           |              `integer`             | Specifies which item (0-indexed) in the field value changed if there are multiple items. If an item was removed, the index will be -1.                                                                                                    |

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

&#x20;If `trigger` equals `addressSelect`, this change event was triggered by the user selecting an [Address Line 1](/platform/build-forms/elements/fields/address/street-address-line-1.md) dropdown option. In that case, `integrationData` contains the address's Google Places address ID (`id`), its individual components, and the latitude / longitude.

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

|      Key      |              Type             | Description                                                                                                                                                                        |
| :-----------: | :---------------------------: | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|      `id`     |            `string`           | The ID of the field that changed.                                                                                                                                                  |
|     `type`    | `enum {field, addressSelect}` | What triggered the field value change. Either a form field was modified or an [Address Line 1](/platform/build-forms/elements/fields/address.md) autocomplete option was selected. |
| `repeatIndex` |           `integer`           | If the element whose value changed repeats, this specifies which repetition it is. This value is 0-indexed and equals 0 if the element doesn't repeat.                             |


---

# Agent Instructions: 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:

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

The question should be specific, self-contained, and written in natural language.
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.
