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

Function cloneObject

src/utils/cloneObject.ts:5–32  ·  view source on GitHub ↗
(data: T)

Source from the content-addressed store, hash-verified

3import isWeb from './isWeb';
4
5export default function cloneObject<T>(data: T): T {
6 if (data instanceof Date) {
7 return new Date(data) as any;
8 }
9
10 const isFileListInstance =
11 typeof FileList !== 'undefined' && data instanceof FileList;
12
13 if (isWeb && (data instanceof Blob || isFileListInstance)) {
14 return data;
15 }
16
17 const isArray = Array.isArray(data);
18
19 if (!isArray && !(isObject(data) && isPlainObject(data))) {
20 return data;
21 }
22
23 const copy = isArray ? [] : Object.create(Object.getPrototypeOf(data));
24
25 for (const key in data) {
26 if (Object.prototype.hasOwnProperty.call(data, key)) {
27 copy[key] = cloneObject(data[key]);
28 }
29 }
30
31 return copy;
32}

Callers 15

appendFunction · 0.85
prependFunction · 0.85
insertFunction · 0.85
updateFunction · 0.85
replaceFunction · 0.85
useFieldArrayFunction · 0.85
useControllerFunction · 0.85
useFormFunction · 0.85
createFormControlFunction · 0.85
setFieldValueFunction · 0.85
_setValueFunction · 0.85
onChangeFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…