Skip to content

Commit 81a5ca6

Browse files
committed
chore: simplify logic
1 parent bf94c42 commit 81a5ca6

File tree

1 file changed

+4
-8
lines changed

1 file changed

+4
-8
lines changed

packages/components/form/hooks/useFormItemInitialData.ts

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -62,24 +62,20 @@ export default function useFormItemInitialData(
6262
}
6363

6464
let defaultInitialData;
65-
let index: number;
66-
let relativePath: NamePath = [];
65+
let index;
66+
let relativePath = [];
6767

6868
if (typeof name === 'number') {
6969
index = name;
7070
} else {
71-
// @ts-ignore
7271
[index, ...relativePath] = name;
7372
}
7473

7574
const itemData = formListInitialData[index];
7675
if (itemData) {
77-
if (Array.isArray(relativePath) && relativePath.length === 0) {
78-
defaultInitialData = itemData;
79-
} else if (typeof itemData === 'object') {
80-
defaultInitialData = get(itemData, relativePath);
81-
}
76+
defaultInitialData = relativePath.length ? get(itemData, relativePath) : itemData;
8277
}
78+
8379
if (typeof defaultInitialData !== 'undefined') return defaultInitialData;
8480
}
8581

0 commit comments

Comments
 (0)