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

Function unregister

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

Source from the content-addressed store, hash-verified

1392 };
1393
1394 const unregister: UseFormUnregister<TFieldValues> = (name, options = {}) => {
1395 for (const fieldName of name ? convertToArrayPayload(name) : _names.mount) {
1396 _names.mount.delete(fieldName);
1397 _names.array.delete(fieldName);
1398
1399 if (!options.keepValue) {
1400 unset(_fields, fieldName);
1401 unset(_formValues, fieldName);
1402 }
1403
1404 !options.keepError && unset(_formState.errors, fieldName);
1405 !options.keepDirty && unset(_formState.dirtyFields, fieldName);
1406 !options.keepTouched && unset(_formState.touchedFields, fieldName);
1407 !options.keepIsValidating &&
1408 unset(_formState.validatingFields, fieldName);
1409 !_options.shouldUnregister &&
1410 !options.keepDefaultValue &&
1411 unset(_defaultValues, fieldName);
1412 }
1413
1414 _subjects.state.next({
1415 values: cloneObject(_formValues),
1416 });
1417
1418 _subjects.state.next({
1419 ..._formState,
1420 ...(!options.keepDirty ? {} : { isDirty: _getDirty() }),
1421 });
1422
1423 !options.keepIsValid && _setValid();
1424 };
1425
1426 const _setDisabledField: Control<TFieldValues>['_setDisabledField'] = ({
1427 disabled,

Callers 11

_removeUnmountedFunction · 0.85
TestComponentFunction · 0.85
ComponentFunction · 0.85
FormFunction · 0.85
AppFunction · 0.85
ComponentFunction · 0.85
useForm.test.tsxFile · 0.85
ComponentFunction · 0.85
ComponentFunction · 0.85
IsValidFunction · 0.85
ConditionFieldFunction · 0.85

Calls 4

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

Tested by 7

TestComponentFunction · 0.68
ComponentFunction · 0.68
FormFunction · 0.68
AppFunction · 0.68
ComponentFunction · 0.68
ComponentFunction · 0.68
ComponentFunction · 0.68

Used in the wild real call sites across dependent graphs

searching dependent graphs…