# @salmonui/inputs/form/state API reference

> 2 exported symbols of @salmonui/inputs/form/state: 1 function and 1 interface.

Canonical: https://salmonui.dev/docs/reference/inputs/form-state

```ts
import { … } from '@salmonui/inputs/form/state';
```

## Functions

### useFormState

Kind: function

Page: https://salmonui.dev/docs/reference/inputs/form-state/useFormState

```ts
function useFormState(): FormState;
```

Dirty tracking against the initial values of a native form:

  const form = useFormState();
  <Form ref={form.ref}>...</Form>
  {form.isDirty ? <Button onClick={form.reset}>Discard</Button> : null}

Initial values are the form's FormData when it mounts; a form that
mounts again (a drawer that opens again, a `key` change after a save)
takes a new snapshot and starts clean. Controlled fields whose value the
parent holds count as dirty until the parent resets them.

## Interfaces

### FormState

Kind: interface

Page: https://salmonui.dev/docs/reference/inputs/form-state/FormState

```ts
interface FormState {
    readonly ref: (form: HTMLFormElement | null) => (() => void) | undefined;
    readonly isDirty: boolean;
    readonly dirtyFields: readonly string[];
    readonly isFieldDirty: (name: string) => boolean;
    readonly reset: () => void;
}
```

What `useFormState()` returns.

Members (5):

| Name | Signature | Flags | Description |
| --- | --- | --- | --- |
| `ref` | `readonly ref: (form: HTMLFormElement \| null) => (() => void) \| undefined;` |  | Attach to the `<form>` (`<Form ref={state.ref}>`); its values on mount are the initial values. |
| `isDirty` | `readonly isDirty: boolean;` |  | True while any field differs from its initial value. |
| `dirtyFields` | `readonly dirtyFields: readonly string[];` |  | Names of the fields whose values differ from the initial ones, in form order. |
| `isFieldDirty` | `readonly isFieldDirty: (name: string) => boolean;` |  | Whether the field `name` differs from its initial value. |
| `reset` | `readonly reset: () => void;` |  | Resets the form (`form.reset()`): every field returns to its `defaultValue`, and the state is clean again. |
