View as Markdown

API reference: @salmonui/inputs/form/state

FormStateinterface

import type { FormState } from '@salmonui/inputs/form/state';
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.

FormState members (5)
NameSignatureDescription
refreadonly ref: (form: HTMLFormElement | null) => (() => void) | undefined;

Attach to the <form> (<Form ref={state.ref}>); its values on mount are the initial values.

isDirtyreadonly isDirty: boolean;

True while any field differs from its initial value.

dirtyFieldsreadonly dirtyFields: readonly string[];

Names of the fields whose values differ from the initial ones, in form order.

isFieldDirtyreadonly isFieldDirty: (name: string) => boolean;

Whether the field name differs from its initial value.

resetreadonly reset: () => void;

Resets the form (form.reset()): every field returns to its defaultValue, and the state is clean again.