MCPcopy
hub / github.com/react-hook-form/react-hook-form / resetField

Function resetField

src/logic/createFormControl.ts:1640–1670  ·  view source on GitHub ↗
(name, options = {})

Source from the content-addressed store, hash-verified

1638 };
1639
1640 const resetField: UseFormResetField<TFieldValues> = (name, options = {}) => {
1641 if (get(_fields, name)) {
1642 if (isUndefined(options.defaultValue)) {
1643 setValue(name, cloneObject(get(_defaultValues, name)));
1644 } else {
1645 setValue(
1646 name,
1647 options.defaultValue as Parameters<typeof setValue<typeof name>>[1],
1648 );
1649 set(_defaultValues, name, cloneObject(options.defaultValue));
1650 }
1651
1652 if (!options.keepTouched) {
1653 unset(_formState.touchedFields, name);
1654 }
1655
1656 if (!options.keepDirty) {
1657 unset(_formState.dirtyFields, name);
1658 _formState.isDirty = options.defaultValue
1659 ? _getDirty(name, cloneObject(get(_defaultValues, name)))
1660 : _getDirty();
1661 }
1662
1663 if (!options.keepError) {
1664 unset(_formState.errors, name);
1665 _proxyFormState.isValid && _setValid();
1666 }
1667
1668 _subjects.state.next({ ..._formState });
1669 }
1670 };
1671
1672 const _reset: UseFormReset<TFieldValues> = (
1673 formValues,

Callers 2

AppFunction · 0.85
AppFunction · 0.85

Calls 5

setValueFunction · 0.85
cloneObjectFunction · 0.85
unsetFunction · 0.85
_getDirtyFunction · 0.85
_setValidFunction · 0.85

Tested by 2

AppFunction · 0.68
AppFunction · 0.68

Used in the wild real call sites across dependent graphs

searching dependent graphs…