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
Latest stable
7.91.0
Last release 1 months ago
23 Oct 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
1103 releases ยท first in 2019
Drag across the ruler to compare, or tap a release to open it.
added support for custom fetcher
๐ Form Component update
fetcher// axios
<Form
action="/api"
method="post"
fetcher={(action, { values }) => axios(action, values)}
/>
// SWR, Tan Query
<Form
action="/api"
method="post"
fetcher={(action, { values }) => mutation(action)}
/>
Beta documenation: http://localhost:8000/api/useform/form
๐๏ธ remove JSX message check (#9921)
```tsx const { control, register, formState: { isSubmitSuccessful, errors } } = useForm({ // progressive: true, optional prop for progressive enhancem
๐ Form Component
const { control, register, formState: { isSubmitSuccessful, errors } } = useForm({
// progressive: true, optional prop for progressive enhancement
});
<Form action="/api" control={control}>
<input {...register('name')} />
{isSubmitSuccessful && <p>Form submit successful.<p>}
{errors?.root?.server && <p>Form submit failed.</p>}
<button>submit</button>
</Form>
const { control, register, formState: { isSubmitSuccessful, errors } } = useForm();
<Form action="/api" control={control} render={({ submit }) => {
<View>
{isSubmitSuccessful && <Text>Form submit successful.<Text>}
{errors?.root?.server && <Text>Form submit failed.</Text>}
<Button onPress={() => submit()} />
</View>
}}/>
export type FormProps<
T extends FieldValues,
U extends FieldValues | undefined = undefined,
> = Partial<{
control: Control<T>;
children?: React.ReactNode | React.ReactNode[];
render?: (props: {
submit: (e?: React.FormEvent) => void;
}) => React.ReactNode | React.ReactNode[];
onSubmit: U extends FieldValues ? SubmitHandler<U> : SubmitHandler<T>;
onSuccess: ({ response }: { response: Response }) => void;
onError: ({
response,
error,
}:
| {
response: Response;
error?: undefined;
}
| {
response?: undefined;
error: unknown;
}) => void;
headers: Record<string, string>;
validateStatus: (status: number) => boolean;
}> &
Omit<React.FormHTMLAttributes<HTMLFormElement>, 'onError'>;
Your coding agent can read these notes before it upgrades. Set up the MCP server โ
๐ close #10195 close async defaultValues not load (#10203) Revert "๐ fix #10139 useFieldArray array error not updating in some cases (#10150)"
๐ close #10195 close async defaultValues not load (#10203) Revert "๐ fix #10139 useFieldArray array error not updating in some cases (#10150)"
๐ชก 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)
๐ 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
One column per quarter.