NewYour coding agent can read the release notes before it upgrades.Set up the MCP server →
npm · #750 most downloaded on npm
Performant, flexible and extensible forms library for React Hooks
Last release 7 days ago
26 Sep 2026
Ships on a steady schedule
a new release about every 2 weeks
Nearly every release is documented
notes for 60 of the last 60 stable releases
Nothing withdrawn
no release was ever pulled
8 years old
1100 releases · first in 2019
🪡 related #10143 did not update dirty until interacted (#10157) 🐞 fix #10139 useFieldArray array error not updating in some cases
🪡 related #10143 did not update dirty until interacted (#10157) 🐞 fix #10139 useFieldArray array error not updating in some cases (#10150)
thanks to @kylemclean
🐞 fix #10131 regression on NaN data type (#10132) 🐞 fix #10129 useFieldArray unmount fieldArray wihtout register (#10130) 🦶 upgrade to TS 5.0.0
🐞 fix #10131 regression on NaN data type (#10132) 🐞 fix #10129 useFieldArray unmount fieldArray wihtout register (#10130) 🦶 upgrade to TS 5.0.0 (#9834)
One column per quarter.
🐞 fix(appendErrors): incorrect type, it can take an array of errors (#10125) ✍️ close #10096 react strict mode with mounted field value (#10102) 🦮 fix
🐞 fix(appendErrors): incorrect type, it can take an array of errors (#10125) ✍️ close #10096 react strict mode with mounted field value (#10102) 🦮 fix: isLoading form state (#10095) 📝 fix: typos in tsdoc (#10088) 🩴 close #10078 prevent stabled aysnc validation (#10082) 🐞 fix #10064 native validation when subscribe to isValid (#10072) 📝 correct typo in field array type declaration (#10066)
thanks to @jorisre @chrisbarless @mjw-isp and @adamtowle
🐰 prevent runtime error with subscribe function (#10052) 🪔 close #10045 improve useController defaultValue restore under strict mode with double useEf
🐰 prevent runtime error with subscribe function (#10052)
🪔 close #10045 improve useController defaultValue restore under strict mode with double useEffect (#10049)
📷 improve form values state update (#10029)
🐞 fix #10021 issue with .next runtime error and fix cypress action
🐞 fix #10021 issue with .next runtime error and fix cypress action (#10026)
📐 fix resetField defaultValue type and reduce any type (#10024) 🐞 fix #9997 issue on the mounted state is updated with values prop (#10001) Revert "🏍
📐 fix resetField defaultValue type and reduce any type (#10024)
🐞 fix #9997 issue on the mounted state is updated with values prop (#10001)
Revert "🏍 delete dirty fields node instead of marking as false (#9156)" (#9996)
💅 improve state subscription consistency (#9984)
🐞 fix #9972 input focus with submitted form (#9978) 💉 improve perf & save some bytes (#9968) 🐞 fix #9955 useForm values prop keepDirtyValues not updat
🐞 fix #9972 input focus with submitted form (#9978)
💉 improve perf & save some bytes (#9968)
🐞 fix #9955 useForm values prop keepDirtyValues not update isDirty (#9959)
🗑️ remove JSX message check (#9921)
🐞 fix #9871 issue with error type (#9873) 🐞 fix #9842 clearErrors method does not support global error
🐞 fix #9871 issue with error type (#9873)
🐞 fix #9842 clearErrors method does not support global error (#9843)
🌏 feature: support global error type #9746
🌏 feature: support global error type #9746
const onSubmit = async () => {
const response = await fetch(...)
if (response.statusCode > 200) {
setError('root.serverError', {
type: response.statusCode,
})
}
}
const onClick = () => {
setError('root.random', {
type: 'random',
})
}
return (
<>
{errors.root.serverError.type === 400 && <p>server response message</p>}
<p>{errors.root?.serverError?.message}</p>
<p>{errors.root?.random?.message}</p>
</>
)
🪜 fix set values for controlled components (#9780)
const { control } = useForm({ values: { test: '' } })
<Controller name="test" /> // no longer throw react warning for uncontrolled become controlled.
🚓 stronger typing to document non-spec attribute uses (#9809)
register('number', {
valueAsNumber: true,
pattern: /[1-4]/g // ❌ type error
})
🏋🏻♀️ reduce package size (#9778) 🧧 reduce unknown and any (#9816)
thanks to @rekliner
const onSubmit = async () => {
setError('root.serverError', {
type: response.statusCode,
});
};
const onClick = () => {
setError('root.random', {
type: 'random',
});
};
return (
<>
{errors.root.serverError.type === 400 && <p>server response message</p>}
<p>{errors.root?.random?.message}</p>
</>
);
🌏 feature: support global error type #9746 ```tsx const onSubmit = () => { const response = await fetch(...) if (response.statusCode > 200) { setError
🌏 feature: support global error type #9746
const onSubmit = () => {
const response = await fetch(...)
if (response.statusCode > 200) {
setError('root.serverError', {
type: response.statusCode,
message: e.message,
})
}
}
const onClick = () => {
setError('root.random', {
type: 'random',
message: 'random'
})
}
return (
<>
{errors.root.serverError.type === 400 && <p>server response message</p>}
<p>{errors.root.serverError.message}</p>
<p>{errors.root.random.message}</p>
</>
)
🪜 fix set defaultValues for controlled components with values props (#9780)
🐞 fix #9773 useFormState missing state update (#9777) 🐞 fix #9765 fix issue with strictMode with isValid state
🐞 fix #9773 useFormState missing state update (#9777) 🐞 fix #9765 fix issue with strictMode with isValid state (#9771)
…error 🙆🏻♂️ fix: revert fieldState.invalid deprecated (#9760) 🇪🇸 fix Spanish translation
📽 feature: validate function to include form values (#9079)
type FormValues = {
number1: number;
number2: number;
};
// Making exported validate function isolated for validation
export function validateNumber(_: number, formValues: FormValues) {
return formValues.number1 + formValues.number2 === 3;
}
export default function App() {
const { register, handleSubmit } = useForm({
defaultValues: {
number1: 0,
number2: 0
}
});
return (
<form onSubmit={handleSubmit((data) => console.log(data))}>
<input
type="number"
{...register("number1", {
validate: validateNumber,
valueAsNumber: true
})}
/>
<input
type="number"
{...register("number2", {
validate: validateNumber,
valueAsNumber: true
})}
/>
<button>submit</button>
</form>
);
}
🛤️ keep track of traversed types to avoid self-referencing while constructing paths for a type (#9540)
🏋🏻♀️ reduced code with unset by weight reduction of 1% (#9575)
📔 fix warning for setValue test case
🪜 Improve handleSubmit function by removing swallow runtime error
🙆🏻♂️ fix: revert fieldState.invalid deprecated (#9760)
🇪🇸 fix Spanish translation (#9737)
thanks to @SimplyLinn & @Mini-ghost @mango906 @amendezm
validate support second argument for form values// Making exported validate function isolated for validation
export function validateNumber(_: number, formValus: FormValues) {
return formValus.number1 + formValus.number2 === 3;
}
<input
type="number"
{...register('number1', {
validate: validateNumber,
valueAsNumber: true,
})}
/>;
handleSubmit no longer catch onSubmit callback errorfieldState.invalid📽 feature: validate function to include formValues
📽 feature: validate function to include formValues (#9079)
type FormValues = {
number1: number;
number2: number;
};
// Making exported validate function isolated for validation
export function validateNumber(_: number, formValus: FormValues) {
return formValus.number1 + formValus.number2 === 3;
}
export default function App() {
const { register, handleSubmit } = useForm({
defaultValues: {
number1: 0,
number2: 0
}
});
return (
<form onSubmit={handleSubmit((data) => console.log(data))}>
<input
type="number"
{...register("number1", {
validate: validateNumber,
valueAsNumber: true
})}
/>
<input
type="number"
{...register("number2", {
validate: validateNumber,
valueAsNumber: true
})}
/>
<button>submit</button>
</form>
);
}
🛤️ keep track of traversed types to avoid self-referencing while constructing paths for a type (#9540)
🏋🏻♀️ reduced code with unset by weight reduce of 1% (#9575)
📔 fix warning for setValue test case
🪜 Improve handleSubmit function
thanks to @SimplyLinn & @Mini-ghost
Nothing published for this version
🐞 fix #9713 regression on validate function with react native
🐞 fix #9713 regression on validate function with react native (#9714)
thanks @Moshyfawn
🐞 fix #9709 calling setValue breaks future onChange calls from a Controller
🐞 fix #9709 calling setValue breaks future onChange calls from a Controller (#9710)
thanks @Moshyfawn
💁♂️ close #9684 revert UnPackAsyncDefaultValues to avoid TS breaking change
💁♂️ close #9684 revert UnPackAsyncDefaultValues to avoid TS breaking change
🤦🏻♂️fix #9661 regression on required valueAsNumber
🤦🏻♂️fix #9661 regression on required valueAsNumber (#9662)
🐞 fix #9659 NaN prevent validation update (#9660) 🕯️ close #9524 useWatch return undefined value (#9653) 📖 adjust contributing document (#9641) 💆🏻 fix
🐞 fix #9659 NaN prevent validation update (#9660)
🕯️ close #9524 useWatch return undefined value (#9653)
📖 adjust contributing document (#9641)
💆🏻 fix #9621 with the inline default value (#9622)
🩻 docs: update contribution guidelines (#9605)
thanks to @Mini-ghost and @stefanpl
…of inputs (#9555) 📔 fix Controller example using deprecated as prop (#9535) 🐞 fix #9521 isValidting property stuck (#9523) 🔨 feat: Migrate to pnpm (#9…
values propsThe following syntax will react to values prop update/changes.
const values = await fetch('API')
useForm({
values, // will reset the form when values updates
// resetOptions: {
// keepDirtyValues: true
// }
})
defaultValues propsThe following syntax will support async defaultValues, so we will manage the reset form internally and update formState accordingly.
useForm() callresetOptions as wellconst { formState: { isLoading } } = useForm({
defaultValues: fetch('API')
// resetOptions: {
// keepDirtyValues: true
// }
})
React use API
useForm({
defaultValues: use(fetch('API'))
// resetOptions: {
// keepDirtyValues: true
// }
})
https://user-images.githubusercontent.com/10513364/208200735-6248b069-9b7d-4bd1-9742-55d1ef8d238a.mov
values and defaultValuesvalues will react to changes and reflect on the form values, and defaultValues is cached for once and will never re-run the promise or react to defaultValues changes.
⏳ close #9525 add isLoading state for async defaultValues (#9526) 🐞 fix #9581 incorrect type for array of string for message (#9584) 🐞 fix #9571 validation issue with unregister input with valueAsNumber (#9572) 🐞 fix(useWatch): default value for array of inputs (#9555) 📔 fix Controller example using deprecated as prop (#9535) 🐞 fix #9521 isValidting property stuck (#9523) 🔨 feat: Migrate to pnpm (#9516) 🎹 fix #9509 incorrect type for WatchObserver (#9510) 🌳 include flush root render method to createFormControl (#9479)
Huge thanks goes to @nvh95's work on PNPM and also thanks to @bell-steven's contribution
useForm added values propsconst values = await fetch('API');
useForm({
values, // will reset the form when values updates
// resetOptions: {
// keepDirtyValues: true
// }
});
isLoading formState for async defaultValuesconst {
formState: { isLoading },
} = useForm();
useForm support async defaultValues propsconst {
formState: { isLoading },
} = useForm({
defaultValues: fetch('API'),
// resetOptions: {
// keepDirtyValues: true
// }
});
🏃🏻♂️ close #9454 set isValid and abort early for the error field
🏃🏻♂️ close #9454 set isValid and abort early for the error field (#9457)
https://user-images.githubusercontent.com/10513364/204661619-af11f963-588b-4e15-8699-970e6a40e48b.mov
🐞 fix #9473 avoid update isDirty & dirtyFields unless flag is passed down (#9475)
thanks @blingblingredstar for the verify
👍 Improved async defaultValues inference
👍 Improved async defaultValues inference
const fetchData = async () => {
await sleep(1000)
return {
data: 'test'
}
}
- useForm<Awaited<ReturnTypeof<typeof fetchData>>>({
+ useForm({
defaultValues: fetchData, // will infer the promise return type
})
👍 Improved useForm resetOptions to keep track of dirty input
- const { formState: { dirtyFields } } = useForm({
+ useForm({ // dirtyFields subscription is no longer required
values,
resetOptions: {
keepDirtyValues; true, // only non dirty input will receive data from the values update
}
})
🪶 improve useFormContext perf by avoiding reference re-create with omit
🦏 close #9410 improve UX when subscribing to both isValid and errors state (#9413)
The following syntax will react to values prop update/changes.
values propsThe following syntax will react to values prop update/changes.
const values = await fetch('API')
useForm({
values, // will reset the form when values updates
// resetOptions: {
// keepDirtyValues: true
// }
})
defaultValues propsThe following syntax will support async defaultValues, so we will manage the reset form internally and update formState accordingly.
useForm() callresetOptions as welluseForm({
defaultValues: fetch('API')
// resetOptions: {
// keepDirtyValues: true
// }
})
React use API
useForm({
defaultValues: use(fetch('API'))
// resetOptions: {
// keepDirtyValues: true
// }
})
values and defaultValuesvalues will react to changes and reflect on the form values, and defaultValues is cached for once and will never re-run the promise or react to defaultValues changes.
🌻 close #9379 flush extra re-render at useFormState to update current form state subscription (#9380) 🍄 upgrade to TS4.9 (#9371)
Revert "🪶 improve useFormContext perf by avoid reference re-create … …with omit (#9407)"
Revert "🪶 improve useFormContext perf by avoid reference re-create … …with omit (#9407)"
🚀 fix fieldArray changes only notify relevant subscribers (#9448) 🪶 improve useFormContext perf by avoid reference re-create with omit ( #9407) 💆🏻 fix
🚀 fix fieldArray changes only notify relevant subscribers (#9448)
🪶 improve useFormContext perf by avoid reference re-create with omit ( #9407)
💆🏻 fix potential watch() global state overwrite (#9450)
🦏 close #9410 improve UX when subscribe to both isValid and errors state (#9413)
🥨 added eslint rule for no-extra-boolean-cast (#9449)
thanks to @elton-okawa
🍄 upgrade to TS4.9 (#9371) 🐞 fix #9383 always updates the errors state for the field array even when the errors subscription missing (#9384) 🌻 close h
🍄 upgrade to TS4.9 (#9371) 🐞 fix #9383 always updates the errors state for the field array even when the errors subscription missing (#9384) 🌻 close https://github.com/react-hook-form/react-hook-form/issues/9379 flush extra re-render to update the current form state subscription 🥽 improve watch logic (#9397) 🔨 fix conditional useFormState test (#9388)
thanks to @romain-trotard
useFormState will trigger an extra re-render to reflect the current formState🐞 fix #9366 useWatch with shadow clone Set data (#9369) 🐞 fix #9365 native validation error persists
🐞 fix #9366 useWatch with shadow clone Set data (#9369)
🐞 fix #9365 native validation error persists (#9370)
🤦 fix #9355 by revert "🥸 related #9310 regression to include actual ref instead custom object ( #9312)"
🤦 fix #9355 by revert "🥸 related #9310 regression to include actual ref instead custom object ( #9312)"
⌨️ close #9339 objects of validation rules type (#9341) 🥸 related #9310 regression to include actual ref instead custom object
⌨️ close #9339 objects of validation rules type (#9341) 🥸 related #9310 regression to include actual ref instead custom object ( #9312)
Revert "🤯 use input reference instead custom object (#9132)"
Revert "🤯 use input reference instead custom object (#9132)" (#9311)
🔮 improve #8601 and remove the relationship between isValid state with mode
🔮 improve #8601 and remove the relationship between isValid state with mode (#9219)
https://user-images.githubusercontent.com/10513364/199356486-bec6cff7-0c33-4076-a60a-e15dc86ddb8a.mov
🐞 fix #9282 regression on async validation block validation (#9286)
🐞 fix #9251 isValidating state stale with resolver (#9254)
🏍 delete dirty fields node instead of marking as false (#9156)
🤯 use input reference instead custom object (#9132)
🥊 improve native reset API invoke (#9293)
🦘 related #9290 improve setCustomValidity logic (#9292)
👺 fix re-render bug with isValid (#9307)
isValid formState is no longer only applicable with onChange, onTouched, and onBlur mode.🕰 support validation for week and time input type
🕰 support validation for week and time input type (#9189)
<input
{...register("week", { min: "2022-W40", max: "2022-W50" })}
type="week"
/>
<input
{...register("time", { min: "11:00", max: "12:00" })}
type="time"
/>
https://user-images.githubusercontent.com/10513364/196547407-8ea7363c-44b8-463e-9aaf-f946a2e5af88.mov
🧘🏻 enable focus error with disabled inputs while submitting (#9155)
🧱 prevent runtime error startsWith called with undefined (#9223)
🐞 fix #9216 isValid state not update with async form level trigger (#9218)
🧦 fix accessibility issue on examples with input missing id (#9174)
🚔 check field array value type before updating (#9170)
📓 update TSDoc for useFieldArray (#9178)
thanks to @BogdanCerovac and @leapful
<input {...register("week", { min: "2022-W40" })} type="week" />
<input {...register("time", { min: "11:00" })} type="time" />
🍨 feature: include defaultValues inside formState
🍨 feature: include defaultValues inside formState (#8966)
const { formState, watch } = useForm({
defaultValues: { name: 'test' }
})
const { defaultValues } = useFormState()
const name = watch('name')
return (
<div>
<p>Your name was {defaultValues.name}</p>
<p>Updated name is {name}</p>
</div>
)
https://user-images.githubusercontent.com/10513364/194426053-454e8e5b-f1c1-4a9d-8428-ac33296c813f.mov
🖨 close #9058 avoid clone object when contains prototype methods
class DataModel {
constructor() {
this.firstName = null
}
}
const formData = new DataModel({ firstName: "Bob" })
useForm({
defaultValues: formData // no longer get clone internally
})
🐞 fix #9134 useFieldArray validation action inconsistency (#9136) 🥷 close #9126 useController ref overwrite under strict mode (#9130) 😵💫 close #9105 improve input focus method check (#9109) 📖 fix UseFieldArrayAppend types example (#9093) 🖇 change link (#9159) 🙌 improve naming of options forEach local (#9152)
thanks to @arieloO @Ilaygoldman and @simenbrekken-visma
defaultValuesconst { formState, watch } = useForm({
defaultValues: { name: 'test' },
});
const { defaultValues } = useFormState();
const name = watch('name');
return (
<div>
<p>Your name was {defaultValues.name}</p>
<p>Updated name is {name}</p>
</div>
);
🍨 feature: include defaultValues inside formState
🍨 feature: include defaultValues inside formState (#8966)
const { formState, watch } = useForm({
defaultValues: { name: 'test' }
})
const { defaultValues } = useFormState()
const name = watch('name')
return (
<div>
<p>Your name was {defaultValues.name}</p>
<p>Updated name is {name}</p>
</div>
)
😵💫 close #9105 improve input focus method check (#9109) 🖨 close #9058 avoid clone object when contains prototype methods
class DataModel {
constructor() {
this.firstName = null
}
}
const formData = new DataModel({ firstName: "Bob" })
useForm({
defaultValues: formData // no longer get clone internally
})
📖 fix UseFieldArrayAppend types example (#9093)
thanks to @arieloO
🪲 fix #9082 inconsistency between single/group of checkboxes disabled check state (#9083) 🌡️ improve setFocus to prevent throw error
🪲 fix #9082 inconsistency between single/group of checkboxes disabled check state (#9083) 🌡️ improve setFocus to prevent throw error (#9081)
🚂 feature: reset to support callback syntax
🚂 feature: reset to support callback syntax (#9051)
reset with partial form values will require invoking getValues at the same time, here is an improvement 👇
Convert your code from:
reset({
...getValues(),
partialData: 'onlyChangeThis'
})
to:
reset((formValues) => {
return {
...formValues,
partialData: 'onlyChangeThis'
}
})
reset((formValues) => {
return {
...formValues,
partialData: 'onlyChangeThis',
};
});
🎉 feature: new type FieldPathByValue field path by value generic implementation
🎉 feature: new type FieldPathByValue field path by value generic implementation
function CustomFormComponent<
TFieldValues extends FieldValues,
Path extends FieldPathByValue<TFieldValues, Date>
>({ control, name }: { control: Control<FieldValues>; name: Path }) {
const { field } = useController({
control,
name,
});
}
function App() {
const { control } = useForm<{
foo: Date;
baz: string;
}>();
return (
<form>
<CustomFormComponent control={control} name="foo" /> {/* no error */}
<CustomFormComponent control={control} name="baz" /> {/* throw an error since baz is string */}
</form>
);
}
🛵 close #8969 improve type for useFieldArray rules validate prop #8974
🛗 upgrade to TS 4.8.0 and Jest 29 #8620
🐞 fix #8970 register field array cause render issue #8972
🐞 fix: typings for useWatch() with no arguments #8923
🐞 fix #8919 make useController fieldState properties enumerable
const { fieldState } = useController({ name: 'test' })
const copy = {...fieldState} ✅
👶🏻 close #8909 form context children prop type (https://github.com/react-hook-form/react-hook-form/pull/8910)
<FormProvider {...methods}>
<div /> // ✅
<div /> // ✅
</FormProvider>
🐌 allow field errors to escape type check when provided with any type 🔐 github workflows security hardening #8965 💚 ci: stop csb ci from publishing a comment on PR (https://github.com/react-hook-form/react-hook-form/pull/8977)
thanks to @Moshyfawn, @sashashura, @carvalheiro, @chetvishal and @MicaelRodrigues
FieldPathByValue field path by value generic implementationfunction CustomFormComponent<
TFieldValues extends FieldValues,
Path extends FieldPathByValue<TFieldValues, Date>,
>({ control, name }: { control: Control<FieldValues>; name: Path }) {
const { field } = useController({
control,
name,
});
}
function App() {
const { control } = useForm<{
foo: Date;
baz: string;
}>();
return (
<form>
<CustomFormComponent control={control} name="foo" /> {/* no error */}
<CustomFormComponent control={control} name="baz" />{' '}
{/* throw an error since baz is string */}
</form>
);
}
<FormProvider {...methods}>
<div /> // ✅
<div /> // ✅
</FormProvider>
🎉 feature: new type FieldPathByValue field path by value generic implementation
🎉 feature: new type FieldPathByValue field path by value generic implementation
function SomeCustomFormComponent<
TFieldValues extends FieldValues,
Path extends FieldPathByValue<TFieldValues, Date>
>({ control, name }: { control: Control<FieldValues>; name: Path }) {
const { field } = useController({
control,
name,
});
return null;
}
function ExampleOfUsage() {
const { control } = useForm<{
foo: Date;
baz: string;
}>();
return (
<div>
<SomeCustomFormComponent control={control} name="foo" />{" "}
{/* throw no error */}
<SomeCustomFormComponent control={control} name="baz" />{" "}
{/* throw an error since baz is string */}
</div>
);
}
🐞 fix https://github.com/react-hook-form/react-hook-form/issues/8919 make useController fieldState properties enumerable
const { fieldState } = useController({ name: 'test' })
const copy = {...fieldState} ✅
👶🏻 close https://github.com/react-hook-form/react-hook-form/issues/8909 form context children prop type (https://github.com/react-hook-form/react-hook-form/pull/8910)
<FormProvider {...methods}>
<div /> // ✅
<div /> // ✅
</FormProvider>
🐌 allow field errors to escape type check when provided with any type
thanks to @carvalheiro, @chetvishal and @MicaelRodrigues
Revert "🧳 let isSubmitting state update after valid form (https://github.com/react-hook-form/react-hook-form/pull/8829)"
Revert "🧳 let isSubmitting state update after valid form (https://github.com/react-hook-form/react-hook-form/pull/8829)"
🐞 fix(path): keys of Date | FileList | File shouldn't be add to the PathImpl https://github.com/react-hook-form/react-hook-form/pull/8804 🐞 fix Date,
🐞 fix(path): keys of Date | FileList | File shouldn't be add to the PathImpl https://github.com/react-hook-form/react-hook-form/pull/8804
🐞 fix Date, FileList, File and Blob FieldErrors mapping #8772
🚌 update isSubmitting state after valid form #8829
function App() {
const { formState: { isSubmitting }, register } = useForm()
console.log(isSubmitting) // isSubmitting will remain false if form is invalid during submission
return <form onSubmit={handleSubmit(async () => await sleep(1000))}>
<input {...register('test', { required: true })} />
</form>
}
🧃 upgrade to cypress 10 #8769 📖 fix nested fields example #8840 📖 add nested form example #8703 📖 improve doc of single watch #8773 📖 fixing typo (Contruído to Construído) on pt-BR translation #8762
thanks to @HarmonyEarth, @yleflour, @glekner, @vemoo, @ronny1020 and @joaoeffting
🎉 feature request: #6879 useFieldArray support rules props
🎉 feature request: #6879 useFieldArray support rules props (#8102)
useFieldArray({
name: 'test',
rules: {
required: true,
minLength: 2,
maxLength: 10,
validate: (fieldArrayValues) => {
if (fieldArrayValues[2].title === 'test') {
return 'validate Error'
}
}
}
})
errors?.test?.root?.message // access root level errors
Note: Related context and poll for error message naming: https://github.com/react-hook-form/react-hook-form/discussions/8625
🐞 fix https://github.com/react-hook-form/react-hook-form/issues/8584: handle nullable nested properties (https://github.com/react-hook-form/react-hook-form/pull/8699) 🆎 close https://github.com/react-hook-form/react-hook-form/issues/8689 fix type inconsistency with control (https://github.com/react-hook-form/react-hook-form/pull/8691) 🐞 fix native form reset isn't executed if first fieldReference isn't a HTMLElement (https://github.com/react-hook-form/react-hook-form/pull/8678) 🐞 fix useFieldArray action type incorrectness (https://github.com/react-hook-form/react-hook-form/pull/8660) 🚔 close https://github.com/react-hook-form/react-hook-form/issues/8653 when useFormContext provide no generic for type check (https://github.com/react-hook-form/react-hook-form/pull/8654) 🛰 useFormContext include type tests (https://github.com/react-hook-form/react-hook-form/pull/8656) 🤣 fix typo in useForm.ts (https://github.com/react-hook-form/react-hook-form/pull/8645) 📚 README Helper / Sponsor Generation Script / Workflow (https://github.com/react-hook-form/react-hook-form/pull/8676)
thanks to @@ANTARES-KOR @zandowc @@alexviar @ElectronicsArchiver and @kyoto7250
useFieldArray with rules propuseFieldArray({
name: 'test',
rules: {
required: true,
minLength: 2,
maxLength: 10,
validate: (fieldArrayValues) => {
if (fieldArrayValues[2].title === 'test') {
return 'validate Error';
}
},
},
});
errors?.test?.root?.message; // access root level errors
🎪 feature request: #6879 useFieldArray support rules props
🎪 feature request: #6879 useFieldArray support rules props (#8102)
useFieldArray({
name: 'test',
rules: {
required: true,
minLength: 2,
maxLength: 10,
validate: (fieldArrayValues) => {
if (fieldArrayValues[2].title === 'test') {
return 'validate Error'
}
}
}
})
errors?.test?.root?.message // access root level errors
Note: Related context and poll for error message naming: https://github.com/react-hook-form/react-hook-form/discussions/8625
🐏 fix https://github.com/react-hook-form/react-hook-form/issues/8584: field errors type with optional fields (https://github.com/react-hook-form/react
🐏 fix https://github.com/react-hook-form/react-hook-form/issues/8584: field errors type with optional fields (https://github.com/react-hook-form/react-hook-form/pull/8591) 🧳 close https://github.com/react-hook-form/react-hook-form/issues/8600 update code example for NestedValue input 🖼 Integrate jest-preview into react-hook-form (https://github.com/react-hook-form/react-hook-form/pull/8577) 🤓 improve the readability of Merge type (https://github.com/react-hook-form/react-hook-form/pull/8570) 🚝 test: migration from ts-jest to @swc/jest (https://github.com/react-hook-form/react-hook-form/pull/8572) 🏹 refactor: use const instead of props (https://github.com/react-hook-form/react-hook-form/pull/8571) 🔍 feat: Add ability to search test file on watch mode (https://github.com/react-hook-form/react-hook-form/pull/8573) 🧘🏻 ensure the field is focused when selected (https://github.com/react-hook-form/react-hook-form/pull/8566)
thanks to @nvh95, @elstgav and @kotarella1110
The deprecation with UnpackNestedValue caused a breaking change on the @hookform/resolvers package, please refer to the changelog and upgrade the reso…
⚛️ upgrade to react 18 (https://github.com/react-hook-form/react-hook-form/pull/8529)
🐞 fix https://github.com/react-hook-form/react-hook-form/issues/8558 missing select function for controlled component (https://github.com/react-hook-form/react-hook-form/pull/8559)
🔬 improve nested field errors type (https://github.com/react-hook-form/react-hook-form/pull/8527)
🗑 UseFormHandleSubmit remove unused generic (https://github.com/react-hook-form/react-hook-form/pull/8526)
👋 deprecate on NestedValue and UnpackNestedValue (https://github.com/react-hook-form/react-hook-form/pull/8528)
type FormValues = {
- select: NestedValue<{
- nested: string
- }>
+ select: {
+ nested: string
+ }
}
errors.select.message ✅
The deprecation with UnpackNestedValue caused a breaking change on the @hookform/resolvers package, please refer to the changelog and upgrade the resolver to the latest.
🥼 close https://github.com/react-hook-form/react-hook-form/issues/8564 update changelog for breaking change with resolver
💥 The above type deprecation cause breaking change with @hookform/resolvers needs to be upgraded to version ^2.9.3 above
Huge thanks go to @felixschorer on type improvement and @romain-trotard for improving tests for react 18
🏋🏻 improve build dist package size (https://github.com/react-hook-form/react-hook-form/pull/8511) 🐞 fix https://github.com/react-hook-form/react-hook-
🏋🏻 improve build dist package size (https://github.com/react-hook-form/react-hook-form/pull/8511)
🐞 fix https://github.com/react-hook-form/react-hook-form/issues/8506 delayError not overwrite existing function call (https://github.com/react-hook-form/react-hook-form/pull/8509)
📖 update the use of validadtionSchema in v7 examples (https://github.com/react-hook-form/react-hook-form/pull/8501)
thanks, @bryantobing12
🐞 fix https://github.com/react-hook-form/react-hook-form/issues/8493 error not trigger with delayError (https://github.com/react-hook-form/react-hook-
🐞 fix https://github.com/react-hook-form/react-hook-form/issues/8493 error not trigger with delayError (https://github.com/react-hook-form/react-hook-form/pull/8494) 🔍 fix null or undefined cases caught by TS ^4.8 (https://github.com/react-hook-form/react-hook-form/pull/8487) 🥸 funnel along with appropriate constraints for (upcoming) TypeScript 4.8 (https://github.com/react-hook-form/react-hook-form/pull/8484)
thanks to @DanielRosenwasser
🎠 feat: make UseFormRegisterReturn generic over TFieldName (https://github.com/react-hook-form/react-hook-form/pull/8414) 🐞 fix https://github.com/rea
🎠 feat: make UseFormRegisterReturn generic over TFieldName (https://github.com/react-hook-form/react-hook-form/pull/8414)
🐞 fix https://github.com/react-hook-form/react-hook-form/issues/8459 regression issue with draft state object (https://github.com/react-hook-form/react-hook-form/pull/8463)
🧾 fix: doc watch() with callback example must deconstruct the returned type (https://github.com/react-hook-form/react-hook-form/pull/8451)
🤝 fix: compare html elements against correct global (https://github.com/react-hook-form/react-hook-form/pull/8355)
🐞 flush errors state update when user switch input with delayError (#8429)
thanks to @omjadas @Pika-Pool and @zenoamaro
UseFormRegisterReturn name type change from string to TFieldName🧑💻 Support TypeScript 4.7+ ESM (https://github.com/react-hook-form/react-hook-form/pull/8390) 🧾 Fix typo (https://github.com/react-hook-form/react-ho
🧑💻 Support TypeScript 4.7+ ESM (https://github.com/react-hook-form/react-hook-form/pull/8390) 🧾 Fix typo (https://github.com/react-hook-form/react-hook-form/pull/8389) ℹ️ fix export types order 🪝 upgrade to TS 4.7 (https://github.com/react-hook-form/react-hook-form/pull/8402) 🕸 close https://github.com/react-hook-form/react-hook-form/issues/8404 use isWeb instead of globalThis (https://github.com/react-hook-form/react-hook-form/pull/8406) 🥬 save cloneObject bytes (https://github.com/react-hook-form/react-hook-form/pull/8407)
thanks to @davbrito, @rossng, @hwanyoungChoi and @Moshyfawn
🐞 fix(reset): set isSubmitted to formState value if keepIsSubmitted is true
🐞 fix(reset): set isSubmitted to formState value if keepIsSubmitted is true (https://github.com/react-hook-form/react-hook-form/pull/8368)
thanks to @blabute
🎭 close #7472 include a proxy check with field state to improve useController perf (#8334) 🐞 fix #8339 Revert "🗑 remove the reference for blob and fil
🎭 close #7472 include a proxy check with field state to improve useController perf (#8334)
🐞 fix #8339 Revert "🗑 remove the reference for blob and file list (https://github.com/react-hook-form/react-hook-form/pull/8305)"
🚮 remove dead code (#8337)
thanks to @NMinhNguyen
🚀 reset optional prop: keepDirtyValues
🚀 reset optional prop: keepDirtyValues (https://github.com/react-hook-form/react-hook-form/pull/8237)
reset(
{
firstName: "bill", // if firstName is dirty then the value will be retained
lastName: "luo"
},
{ keepDirtyValues: true } // keep any changed field
);
👩🔧 close https://github.com/react-hook-form/react-hook-form/issues/8324 auto-correct field array errors on user action (https://github.com/react-hook-form/react-hook-form/pull/8325)
const { append } = useFieldArray()
append({ data: '' }) // will auto correct existing field array errors if any
🐞 fix: clone objects which have functions (https://github.com/react-hook-form/react-hook-form/pull/8301) 📖 fix name of a new option in 6.12.0 change-log notes (https://github.com/react-hook-form/react-hook-form/pull/8335)
thanks to @Moshyfawn @airman5573 @TkDodo and @MasterOdin
reset optional prop: keepDirtyValuesreset(
{
firstName: 'bill', // if firstName is dirty then the value will be retained
lastName: 'luo',
},
{ keepDirtyValues: true }, // keep any changed field
);
useFieldArray auto-correct field array errors on user actionconst { append } = useFieldArray();
append({ data: '' }); // will auto correct existing field array errors if any
🐣 determine checkbox group by defaultValues set as array value
🐣 determine checkbox group by defaultValues set as array value (https://github.com/react-hook-form/react-hook-form/pull/7938)
useForm({
defaultValues: {
checkboxes: [], // register checkbox will be determine as array of checkboxes
},
});
register('checkboxes'); // will return array as value
🧪 improve test cases with checkbox default value as array (https://github.com/react-hook-form/react-hook-form/pull/7501) 📕 add fieldState invalid depreciation note (https://github.com/react-hook-form/react-hook-form/pull/8202) ⛑ improve getNodeParentName missing case(s) (https://github.com/react-hook-form/react-hook-form/pull/8181) 🔨 support field array parents with numbers in name (https://github.com/react-hook-form/react-hook-form/pull/8167) 💉 improve lib tests cases (https://github.com/react-hook-form/react-hook-form/pull/8155)
Thanks to contributors below ❤️
useForm({
defaultValues: {
checkboxes: [], // register checkbox will be determine as array of checkboxes
},
});
register('checkboxes'); // will return array as value
❤️ update react 18 peer dep 📦 es2017 to es2018 (https://github.com/react-hook-form/react-hook-form/pull/8066) Reduce 1% of package weight 🏃 avoid runt
❤️ update react 18 peer dep
📦 es2017 to es2018 (https://github.com/react-hook-form/react-hook-form/pull/8066) Reduce 1% of package weight
🏃 avoid runtime error with compact (https://github.com/react-hook-form/react-hook-form/pull/8094)
👋 goodbye omit (https://github.com/react-hook-form/react-hook-form/pull/8079)
🐞 close https://github.com/react-hook-form/react-hook-form/issues/8071 issue on shouldUnreigster mutate defaultValues (https://github.com/react-hook-form/react-hook-form/pull/8078)
⏭️ close https://github.com/react-hook-form/react-hook-form/issues/8076 isMount flag issue with useEffect running twice with react 18 (https://github.com/react-hook-form/react-hook-form/pull/8077)
🎧 close https://github.com/react-hook-form/react-hook-form/issues/8071 clean up at useForm useEffect (https://github.com/react-hook-form/react-hook-form/pull/8073)
🐞 fix https://github.com/react-hook-form/react-hook-form/issues/8050 disabled attribute ignored with register checkbox (https://github.com/react-hook-
🐞 fix https://github.com/react-hook-form/react-hook-form/issues/8050 disabled attribute ignored with register checkbox (https://github.com/react-hook-form/react-hook-form/pull/8053) 📦 update package.json to set sideEffect false (https://github.com/react-hook-form/react-hook-form/pull/8041) 🆙 TS 4.6.0 (https://github.com/react-hook-form/react-hook-form/pull/7623) 📖 fix replace API TSDoc for fieldArray
thanks to @alexogar and @Moshyfawn
🏬 enable deps with string syntax (https://github.com/react-hook-form/react-hook-form/pull/7901) `tsx register('test', { deps: 'theOtherInput' }) regis
🏬 enable deps with string syntax (https://github.com/react-hook-form/react-hook-form/pull/7901)
register('test', { deps: 'theOtherInput' })
register('test', { deps: ['theOtherInput', 'others'] })
🧷 fix field array update to avoid external mutation
🐞 fix https://github.com/react-hook-form/react-hook-form/issues/7960 issue on unset deeply nested array field (https://github.com/react-hook-form/react-hook-form/pull/7961)
🐞 fix https://github.com/react-hook-form/react-hook-form/issues/7958 issue with checkbox plus portal (https://github.com/react-hook-form/react-hook-form/pull/7959)
📦 unpack blob data type (https://github.com/react-hook-form/react-hook-form/pull/7937)
thanks to @DASPRiD and @Moshyfawn
register API options deps now support stringregister('test', { deps: 'test' });
🏬 enable deps with string syntax (https://github.com/react-hook-form/react-hook-form/pull/7901) `tsx register('test', { deps: 'theOtherInput' }) 🧷 fix
🏬 enable deps with string syntax (https://github.com/react-hook-form/react-hook-form/pull/7901)
register('test', { deps: 'theOtherInput' })
🧷 fix field array update to avoid external mutation
🐛 fix https://github.com/react-hook-form/react-hook-form/issues/7853 (useFieldArray): pass context type down to Control (https://github.com/react-hook
🐛 fix https://github.com/react-hook-form/react-hook-form/issues/7853 (useFieldArray): pass context type down to Control (https://github.com/react-hook-form/react-hook-form/pull/7856) 🐞 fix https://github.com/react-hook-form/react-hook-form/issues/7849 issue with unset on multiple dimension array (https://github.com/react-hook-form/react-hook-form/pull/7859)
thanks to @Moshyfawn
✨ https://github.com/react-hook-form/react-hook-form/issues/7138 feature: allow selecting input's content on focus
✨ https://github.com/react-hook-form/react-hook-form/issues/7138 feature: allow selecting input's content on focus (https://github.com/react-hook-form/react-hook-form/pull/7781)
setFocus('fieldName', { shouldSelect: true })
https://user-images.githubusercontent.com/10513364/153570934-ca29337f-d7ce-4744-b282-6939c2e17b48.mp4
⌨️ fix https://github.com/react-hook-form/react-hook-form/issues/7772 type issue by using UnpackNestedValue on FieldArray methods (https://github.com/react-hook-form/react-hook-form/pull/7773)
thanks to @Moshyfawn and @hpersson
setFocus to select the entire field valuesetFocus('fieldName', { shouldSelect: true });
🐞 close https://github.com/react-hook-form/react-hook-form/issues/7758 useController should subscribe to exact field name
🐞 close https://github.com/react-hook-form/react-hook-form/issues/7758 useController should subscribe to exact field name (https://github.com/react-hook-form/react-hook-form/pull/7759)
thanks to @Moshyfawn
https://user-images.githubusercontent.com/10513364/152477495-7df7269c-18c2-4420-85e7-956c7c35ca42.mp4
📚 TSDoc
https://user-images.githubusercontent.com/10513364/152477495-7df7269c-18c2-4420-85e7-956c7c35ca42.mp4
🐞 fix https://github.com/react-hook-form/react-hook-form/issues/7741 is validating reset when async validations are still running (https://github.com/react-hook-form/react-hook-form/pull/7747) ⛑ close https://github.com/react-hook-form/react-hook-form/issues/7717 shallow clone errors object in handleSubmit (https://github.com/react-hook-form/react-hook-form/pull/7718) 🍦 close https://github.com/react-hook-form/react-hook-form/issues/7703 don't expose internal state in handleSubmit (https://github.com/react-hook-form/react-hook-form/pull/7704) 🏋️ save bytes on parseFloat (https://github.com/react-hook-form/react-hook-form/pull/7697)
thanks to @Moshyfawn and @tiii
Your coding agent can read these notes before it upgrades. Set up the MCP server →