Is your feature request related to a problem? Please describe.
It happens quite often in dynamic forms that some field is displayed / hidden based on the value of another field. To implement something like this, we can either use the watch return from useForm or the useWatch hook.
The issue with using watch is that the re-renders are not isolated to only the component that needs the data.
useWatch allow us to subscribe to a value and isolate re-render, but we have to extract the conditional rendered field in its own component, making it unclear by looking at the form one field will be displayed / hidden based on another field value.
Describe the solution you'd like
It would be nice for RHF to also expose a Watch component, which would be a thin wrapper around the useWatch hook, but allow to compose without having to break down in multiple components:
const { register } = useForm({ ... });
return (
<form>
<input type="checkbox" {...register('hasPet')} />
<Watch name="hasPet">
{(hasPet) => hasPet ? <input type="text" {...register('petName') /> : null}
</Watch>
</form>
Is your feature request related to a problem? Please describe.
It happens quite often in dynamic forms that some field is displayed / hidden based on the value of another field. To implement something like this, we can either use the
watchreturn fromuseFormor theuseWatchhook.The issue with using
watchis that the re-renders are not isolated to only the component that needs the data.useWatchallow us to subscribe to a value and isolate re-render, but we have to extract the conditional rendered field in its own component, making it unclear by looking at the form one field will be displayed / hidden based on another field value.Describe the solution you'd like
It would be nice for RHF to also expose a
Watchcomponent, which would be a thin wrapper around theuseWatchhook, but allow to compose without having to break down in multiple components: