From 49ff6e50d6faf877330fc3acf01396118935baa9 Mon Sep 17 00:00:00 2001 From: zombiej Date: Tue, 28 Apr 2020 23:30:33 +0800 Subject: [PATCH] fix raw type --- src/Body/BodyRow.tsx | 3 +-- src/Table.tsx | 4 ++-- tests/Table.spec.js | 10 ++++++++++ 3 files changed, 13 insertions(+), 4 deletions(-) diff --git a/src/Body/BodyRow.tsx b/src/Body/BodyRow.tsx index 412172393..8952b4964 100644 --- a/src/Body/BodyRow.tsx +++ b/src/Body/BodyRow.tsx @@ -70,8 +70,7 @@ function BodyRow(props: BodyRowP const rowSupportExpand = expandableType === 'row' && (!rowExpandable || rowExpandable(record)); // Only when row is not expandable and `children` exist in record const nestExpandable = expandableType === 'nest'; - const hasNestChildren = - childrenColumnName && childrenColumnName in record && record[childrenColumnName]; + const hasNestChildren = childrenColumnName && record && record[childrenColumnName]; const mergedExpandable = rowSupportExpand || nestExpandable; // =========================== onRow =========================== diff --git a/src/Table.tsx b/src/Table.tsx index b0cb746aa..707c1c9ec 100644 --- a/src/Table.tsx +++ b/src/Table.tsx @@ -233,7 +233,7 @@ function Table(props: TableProps { - const key = record[rowKey]; + const key = record && record[rowKey]; if (process.env.NODE_ENV !== 'production') { warning( @@ -284,7 +284,7 @@ function Table(props: TableProps mergedChildrenColumnName in record) + mergedData.some(record => record && record[mergedChildrenColumnName]) ) { return 'nest'; } diff --git a/tests/Table.spec.js b/tests/Table.spec.js index 8d9633e64..718c3765c 100644 --- a/tests/Table.spec.js +++ b/tests/Table.spec.js @@ -915,4 +915,14 @@ describe('Table.Basic', () => { wrapper.setState({ change: true }); expect(wrapper.find('td').text()).toEqual('true'); }); + + it('not crash with raw data', () => { + expect(() => { + mount( + createTable({ + data: [122, null, '2333', true, undefined], + }), + ); + }).not.toThrow(); + }); });