From d75a40c77f78656ffc147979e65d497933d4f58a Mon Sep 17 00:00:00 2001 From: Benedict de Silva Date: Fri, 25 Feb 2022 10:24:57 +0000 Subject: [PATCH] Update TableComponent.tsx to use `deepClone` function instead of spread syntax When using the table within a block editor, having created a table, left the document and returned, adding a new row/s would result in an 'can't define property "x": "obj" is not extensible' error in the console. Both the `addRows` and `addRowAt` functions were using spread syntax when assigning the `newValue` const, rather than using the `deepClone` function which is used by all other functions, which resulted in the error. --- src/TableComponent.tsx | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/TableComponent.tsx b/src/TableComponent.tsx index 63d925d..ac99e84 100644 --- a/src/TableComponent.tsx +++ b/src/TableComponent.tsx @@ -56,7 +56,7 @@ const TableComponent: FunctionComponent = (props) => { }; const addRows = (count: number = 1) => { - const newValue = { ...value }; + const newValue = deepClone(value); // Calculate the column count from the first row const columnCount = value.rows[0].cells.length; for (let i = 0; i < count; i++) { @@ -71,7 +71,7 @@ const TableComponent: FunctionComponent = (props) => { }; const addRowAt = (index: number = 0) => { - const newValue = { ...value }; + const newValue = deepClone(value); // Calculate the column count from the first row const columnCount = value.rows[0].cells.length;