Skip to content

Commit 17d1bb4

Browse files
authored
fix raw type (#464)
1 parent 7bd234b commit 17d1bb4

File tree

3 files changed

+13
-4
lines changed

3 files changed

+13
-4
lines changed

src/Body/BodyRow.tsx

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,8 +70,7 @@ function BodyRow<RecordType extends { children?: RecordType[] }>(props: BodyRowP
7070
const rowSupportExpand = expandableType === 'row' && (!rowExpandable || rowExpandable(record));
7171
// Only when row is not expandable and `children` exist in record
7272
const nestExpandable = expandableType === 'nest';
73-
const hasNestChildren =
74-
childrenColumnName && childrenColumnName in record && record[childrenColumnName];
73+
const hasNestChildren = childrenColumnName && record && record[childrenColumnName];
7574
const mergedExpandable = rowSupportExpand || nestExpandable;
7675

7776
// =========================== onRow ===========================

src/Table.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -233,7 +233,7 @@ function Table<RecordType extends DefaultRecordType>(props: TableProps<RecordTyp
233233
return rowKey;
234234
}
235235
return (record: RecordType) => {
236-
const key = record[rowKey];
236+
const key = record && record[rowKey];
237237

238238
if (process.env.NODE_ENV !== 'production') {
239239
warning(
@@ -284,7 +284,7 @@ function Table<RecordType extends DefaultRecordType>(props: TableProps<RecordTyp
284284
(props.expandable &&
285285
internalHooks === INTERNAL_HOOKS &&
286286
(props.expandable as any).__PARENT_RENDER_ICON__) ||
287-
mergedData.some(record => mergedChildrenColumnName in record)
287+
mergedData.some(record => record && record[mergedChildrenColumnName])
288288
) {
289289
return 'nest';
290290
}

tests/Table.spec.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -915,4 +915,14 @@ describe('Table.Basic', () => {
915915
wrapper.setState({ change: true });
916916
expect(wrapper.find('td').text()).toEqual('true');
917917
});
918+
919+
it('not crash with raw data', () => {
920+
expect(() => {
921+
mount(
922+
createTable({
923+
data: [122, null, '2333', true, undefined],
924+
}),
925+
);
926+
}).not.toThrow();
927+
});
918928
});

0 commit comments

Comments
 (0)