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

Function unset

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

Source from the content-addressed store, hash-verified

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

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

Used in the wild real call sites across dependent graphs

searching dependent graphs…