Capítulo 25 de 39
unregister(name, options?) removes a registered input's reference (and, by default, its built-in validation rules), with keepX flags to selectively preserve pieces of its state.
firstName stays required per a Yup/Zod schema even after unregister("firstName").unregister("yourDetails") clears the whole nested object; unregister("yourDetails.firstName") clears just that leaf, leaving siblings.keepDirty/keepIsValid don't guarantee the next user action won't recompute them anyway (both are measured live against defaultValues/schema). keepDefaultValue only matters when the form's top-level shouldUnregister is false (the default) — it's a no-op when shouldUnregister: true.unregister while the <input {...register(...)}> stays mounted just gets it re-registered — pair the call with removing/hiding the element.unregister("yourDetails") // {} — whole nested object gone
unregister("yourDetails.firstName") // { lastName: '' } — one leaf gone
unregister(["yourDetails.lastName"]) // { firstName: '' } — array form
const onClick = () => {
unregister("test")
setShow(false) // must also unmount, or register() re-adds it
}
{show && <input {...register("test")} />}
unregister with actually removing the input from the tree.unregister without unmounting the corresponding input: the input's own register call re-adds it on the next render.unregister to remove a resolver/schema's validation rule for that field: it only clears RHF's internal reference/rules, not the schema itself.unregister and unmounting the input go together — neither alone fully removes a field.unregister; adjust the schema itself if needed.keep* options are best-effort preservation, not permanent guarantees against later recomputation.register persist past unmount unless explicitly unregistered (or shouldUnregister is set).shouldUnregister option this method's keepDefaultValue interacts with.