MCPcopy Create free account
hub / github.com/react-hook-form/react-hook-form / unset

Function unset

src/utils/unset.ts:28–58  ·  view source on GitHub ↗
(object: any, path: string | (string | number)[])

Source from the content-addressed store, hash-verified

26}
27
28export default function unset(object: any, path: string | (string | number)[]) {
29 if (isString(path) && Object.prototype.hasOwnProperty.call(object, path)) {
30 delete object[path];
31 return object;
32 }
33
34 const paths = Array.isArray(path)
35 ? path
36 : isKey(path)
37 ? [path]
38 : stringToPath(path);
39
40 const childObject = paths.length === 1 ? object : baseGet(object, paths);
41
42 const index = paths.length - 1;
43 const key = paths[index];
44
45 if (childObject) {
46 delete childObject[key];
47 }
48
49 if (
50 index !== 0 &&
51 ((isObject(childObject) && isEmptyObject(childObject)) ||
52 (Array.isArray(childObject) && isEmptyArray(childObject)))
53 ) {
54 unset(object, paths.slice(0, -1));
55 }
56
57 return object;
58}

Callers 12

useFieldArrayFunction · 0.85
_updateIsValidatingFunction · 0.85
updateTouchAndDirtyFunction · 0.85
shouldRenderByErrorFunction · 0.85
executeBuiltInValidationFunction · 0.85
clearErrorsFunction · 0.85
unregisterFunction · 0.85
handleSubmitFunction · 0.85
resetFieldFunction · 0.85
unsetEmptyArray.tsFile · 0.85
unset.test.tsFile · 0.85

Calls 2

baseGetFunction · 0.85
isEmptyArrayFunction · 0.85

Tested by

no test coverage detected