Skip to content

useForm

Creates mutable form state from a structured clone of an initial specification. Calling reset() restores a fresh clone of that original shape, which is useful after submitting or cancelling a form.

Importing

ts
import { useForm } from '@almighty-shogun/vue-utils'

Usage

ts
import { useForm } from '@almighty-shogun/vue-utils'

const { form, reset } = useForm({ email: '', password: '' });

form.value.email = 'ada@example.com';
reset();

Parameters

NameTypeDescription
specTInitial form shape.

Returns

NameTypeDescription
formRef<T>Mutable form state cloned from the initial spec.
reset()() => voidReplaces form.value with a fresh clone of the original spec.

Type signature

ts
declare function useForm<T>(spec: T): UseForm<T>;

type UseForm<T> = {
    readonly form: Ref<T>;

    reset(): void;
};

All packages are released under the MIT License.