> ## Documentation Index
> Fetch the complete documentation index at: https://developers.telnyx.com/llms.txt
> Use this file to discover all available pages before exploring further.

# onStateChanged()

> `protected` **onStateChanged**(`_next`, `_prev`): `Promise`\<`void`>

Hook: fires after every persistent state change — after each
[`setState`](/docs/agent-sdk/interface/setState) **and**
[`replaceState`](/docs/agent-sdk/interface/replaceState) resolves.

Override to react to changes: mirror state to an external system, log
transitions, invalidate caches, or fan state out to connected clients.
The default implementation does nothing.

**Parameters**

| Parameter | Type | Description |
| - | - | - |
| `_next` | `State` | The state after the change. |
| `_prev` | `State` | The state before the change. |

**Returns**

`Promise`\<`void`>
