# StateOptions

Canonical page: https://www.adaptabletools.com/docs/reference/stateoptions

Options related to Adaptable State hydration / dehydration; allows users to intercept state persistence and loading with custom functionality

All functions deal with `AdaptablePersistentState` - the persisted subset of `AdaptableState`.
Transient sections (`Internal`, `Popup`, `Comment`, `Plugins`) are never passed to, nor expected from, these functions.

Hydration flow: `loadState()` - (merge with `initialState`) - `applyState()`

Dehydration flow: `saveState()` - `persistState()`

To store Adaptable State in a custom format (e.g. wrapped in an envelope, compressed, encrypted) do the wrapping in `persistState()` and the unwrapping in `loadState()` - these are the only functions which own the storage format.
`saveState()` and `applyState()` always operate on Adaptable State, as `loadState()`&#39;s result is merged with `initialState` section by section before `applyState()` is called.

```ts title="TypeScript"
export interface StateOptions 
```

## Properties

| Property | Type | Description | Default |
| --- | --- | --- | --- |
| [applyState](https://www.adaptabletools.com/docs/reference/stateoptions.md#applystate) | [`AdaptableApplyStateFunction`](https://www.adaptabletools.com/docs/reference/adaptableapplystatefunction.md) | Transforms state before applying it to the application. Called after `loadState()` (and after merging with `initialState`) but before the state is used. |   |
| [autoMigrateState](https://www.adaptabletools.com/docs/reference/stateoptions.md#automigratestate) | `boolean` | Automatically migrate State from previous AdapTable version to current one | true |
| [clearState](https://www.adaptabletools.com/docs/reference/stateoptions.md#clearstate) | [`AdaptableClearStateFunction`](https://www.adaptabletools.com/docs/reference/adaptableclearstatefunction.md) | Allows clearing of remote Adaptable State. Only invoked during `StateApi.reloadInitialState()` operations. | undefined |
| [debounceStateDelay](https://www.adaptabletools.com/docs/reference/stateoptions.md#debouncestatedelay) | `number` | Delay (in ms) to debounce `saveState` / `persistState` calls enabling grouping multiple sequential calls in single one (e.g. elevator doors)<br/><br/>**Defaults to: 400**. Also, the wait will be max 1000ms, at which point the save/persist calls will happen anyway. | 400 |
| [loadState](https://www.adaptabletools.com/docs/reference/stateoptions.md#loadstate) | [`AdaptableLoadStateFunction`](https://www.adaptabletools.com/docs/reference/adaptableloadstatefunction.md) | Retrieves saved Adaptable State from storage or external source |   |
| [persistState](https://www.adaptabletools.com/docs/reference/stateoptions.md#persiststate) | [`AdaptablePersistStateFunction`](https://www.adaptabletools.com/docs/reference/adaptablepersiststatefunction.md) | Handles the actual storage of state to localStorage, server, etc. Called after `saveState()` to store the prepared state. |   |
| [saveState](https://www.adaptabletools.com/docs/reference/stateoptions.md#savestate) | [`AdaptableSaveStateFunction`](https://www.adaptabletools.com/docs/reference/adaptablesavestatefunction.md) | Transforms state before saving to storage. Called before `persistState()`. |   |

## Property Details

### applyState

Transforms state before applying it to the application. Called after `loadState()` (and after merging with `initialState`) but before the state is used.

```ts title="TypeScript"
applyState?: AdaptableApplyStateFunction;
```

###### Property Value

[`AdaptableApplyStateFunction`](https://www.adaptabletools.com/docs/reference/adaptableapplystatefunction.md)

### autoMigrateState

Automatically migrate State from previous AdapTable version to current one

```ts title="TypeScript"
autoMigrateState?: boolean;
```

###### Default Value

true

###### Property Value

`boolean`

### clearState

Allows clearing of remote Adaptable State. Only invoked during `StateApi.reloadInitialState()` operations.

```ts title="TypeScript"
clearState?: AdaptableClearStateFunction;
```

###### Default Value

undefined

###### Property Value

[`AdaptableClearStateFunction`](https://www.adaptabletools.com/docs/reference/adaptableclearstatefunction.md)

### debounceStateDelay

Delay (in ms) to debounce `saveState` / `persistState` calls enabling grouping multiple sequential calls in single one (e.g. elevator doors)

**Defaults to: 400**. Also, the wait will be max 1000ms, at which point the save/persist calls will happen anyway.

```ts title="TypeScript"
debounceStateDelay?: number;
```

###### Default Value

400

###### Property Value

`number`

### loadState

Retrieves saved Adaptable State from storage or external source

```ts title="TypeScript"
loadState?: AdaptableLoadStateFunction;
```

###### Property Value

[`AdaptableLoadStateFunction`](https://www.adaptabletools.com/docs/reference/adaptableloadstatefunction.md)

### persistState

Handles the actual storage of state to localStorage, server, etc. Called after `saveState()` to store the prepared state.

```ts title="TypeScript"
persistState?: AdaptablePersistStateFunction;
```

###### Property Value

[`AdaptablePersistStateFunction`](https://www.adaptabletools.com/docs/reference/adaptablepersiststatefunction.md)

### saveState

Transforms state before saving to storage. Called before `persistState()`.

```ts title="TypeScript"
saveState?: AdaptableSaveStateFunction;
```

###### Property Value

[`AdaptableSaveStateFunction`](https://www.adaptabletools.com/docs/reference/adaptablesavestatefunction.md)
