API reference > @kontsedal/olas-react > useField
useField() function โ
Subscribe to all signals on a Field<T> with a single useSyncExternalStore call. Returns the plain values plus the action methods so a binding to an<input> is one destructure. See spec ยง20.10.
Signature:
typescript
export declare function useField<T>(field: Field<T>): UseFieldResult<T>;Parameters โ
Parameter | Type | Description |
|---|---|---|
field | Field<T> |
Returns:
Example โ
tsx
function NameInput({ field }: { field: Field<string> }) {
const f = useField(field)
return (
<label>
<input value={f.value} onChange={(e) => f.set(e.target.value)} onBlur={f.markTouched} />
{f.touched && f.errors[0] && <em>{f.errors[0]}</em>}
</label>
)
}