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/common'Usage
ts
import { useForm } from '@almighty-shogun/common'
const { form, reset } = useForm({ email: '', password: '' });
form.value.email = 'ada@example.com';
reset();Parameters
spec: T
Initial form shape.
Returns
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;
};