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
| Name | Type | Description |
|---|---|---|
spec | T | Initial form shape. |
Returns
| Name | Type | Description |
|---|---|---|
form | Ref<T> | Mutable form state cloned from the initial spec. |
reset() | () => void | Replaces 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;
};