useFormField
Alias of useField.
Import
TypeScript
import { useFormField } from '@/hooks';API
Signature
useFormField(options) → field API
When to use
Use useFormField instead of re-implementing the same pattern in multiple components.
SSR / Next.js
SSR-safe state machines.
Live playground
Edit the example and see it run against the real @/hooks package in this app.
Live playgroundEdit · run with real
@/hooks · useFormFieldEditor
function Name() { const name = useFormField({ initialValue: '' }); return <input value={name.value} onChange={name.onChange} />; }
Preview
Implementation source
Full library source for useFormField — copy into your project when you are not installing a package yet.
hooks/forms/useFormField.ts
import { useField, type UseFieldOptions, type UseFieldReturn } from './useField';
/** Alias of {@link useField}. */
export function useFormField<T>(options: UseFieldOptions<T>): UseFieldReturn<T> {
return useField(options);
}
Copy-paste example
useFormField.example.tsx
'use client';
import { useFormField } from '@/hooks';
export function Name() {
const name = useFormField({ initialValue: '' });
return <input value={name.value} onChange={name.onChange} />;
}Production checklist
- Called only from Client Components or other custom hooks
- Type parameters filled in (e.g.
useFetch<User[]>) - Tip: Field name attributes must match keys in initialValues for handleChange.
- Source of truth: open
hooks/forms/useFormField.tsfor implementation details