Community JavaScript Snippet

useFormField Hook With Field-Level Validation

A field-scoped form hook for the cases where react-hook-form is overkill. Tracks value, touched, blur, and an async validator with a single race-safe in-flight token.

useFormField Hook With Field-Level Validation

A field-scoped form hook for the cases where react-hook-form is overkill. Tracks value, touched, blur, and an async validator with a single race-safe in-flight token.

JavaScript
Frontend
3 snippets
react
hooks
code-template
error-handling
leoeriksson

By @leoeriksson

February 23, 2026

·

Updated May 20, 2026

729 views

13

4.5 (10)

The trick to making useFormField ergonomic is the inputProps object: consumers spread it on a JSX element and the hook owns every piece of behavior. I keep error as a derived value from useMemo, not state, because then validators are pure and a fresh validator function (closing over a different prop) takes effect immediately. The showError boolean encapsulates the rule that we only show the error AFTER the user has blurred the field once, which is the single biggest reason form UX feels respectful or hostile. Reset takes the form back to its original state and is the function I forget to expose half the time.