From 4b2686ae79328d219e85a2a0ebd8b853bd8a68c0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marc=20Gu=CC=88ell=20Segarra?= Date: Sun, 10 Sep 2023 13:31:32 +0200 Subject: [PATCH] Fix conditional rendering hook issue --- package-lock.json | 4 ++-- package.json | 2 +- src/Table.tsx | 23 +++++++++++++++-------- 3 files changed, 18 insertions(+), 11 deletions(-) diff --git a/package-lock.json b/package-lock.json index 2628ea2..04a35dc 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "@gisce/react-formiga-table", - "version": "0.8.5", + "version": "0.8.6", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "@gisce/react-formiga-table", - "version": "0.8.5", + "version": "0.8.6", "dependencies": { "react": "^16.8.0 || 17.x", "react-dom": "^16.8.0 || 17.x", diff --git a/package.json b/package.json index f08cf2c..26ee932 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@gisce/react-formiga-table", - "version": "0.8.5", + "version": "0.8.6", "scripts": { "build": "tsc && vite build", "prepublishOnly": "npm run build", diff --git a/src/Table.tsx b/src/Table.tsx index a663ad4..59c5ecf 100644 --- a/src/Table.tsx +++ b/src/Table.tsx @@ -27,20 +27,19 @@ export const Table = (props: TableProps) => { selectionRowKeys: selectionRowKeysProps, } = props; - if (loading) { - return loadingComponent; - } - const { selectedRowKeys, toggleAllRowsSelected, isRowSelected, changeSelected, } = useSelectable({ - selectionRowKeysProps + selectionRowKeysProps, }); - - const onChange = useShiftSelected(dataSource.map(el => el.id), changeSelected); + + const onChange = useShiftSelected( + dataSource.map((el) => el.id), + changeSelected + ); const { localSorter, getColumnSorter, handleColumnClick } = useSortable(sorter); @@ -80,8 +79,16 @@ export const Table = (props: TableProps) => { toggleAllRowsSelected(getAllVisibleKeys()); }, [toggleAllRowsSelected, getAllVisibleKeys]); + if (loading) { + return loadingComponent; + } + return ( - +