Skip to main content

Conditional Fields

There will be times when you want to conditionally render a field based on the value or values of other fields. React Hook Form supports that out of the box with ease. You can use as DependentField as so:

<TextField name="dob" />
<DependentField<{ dob: Date; favoriteDrink?: string; }>
name="favoriteDrink"
dependencies={(values) => ({ dob: values.dob })}
as={({ input, dependencies }) => {
if (dependencies.dob < 21) return null;
return <TextInput />
}}
/>