Просмотр исходного кода

Added a min of 1 to the page size so it doesn't throw invalid array length error

jnfrati 4 лет назад
Родитель
Сommit
ffd1072a20
1 измененных файлов с 4 добавлено и 1 удалено
  1. 4 1
      dashboard/src/components/Table.tsx

+ 4 - 1
dashboard/src/components/Table.tsx

@@ -41,6 +41,8 @@ export type TableProps = {
   enablePagination?: boolean;
 };
 
+const MIN_PAGE_SIZE = 1;
+
 const Table: React.FC<TableProps> = ({
   columns: columnsData,
   data,
@@ -73,6 +75,7 @@ const Table: React.FC<TableProps> = ({
     {
       columns: columnsData,
       data,
+      initialState: { pageSize: MIN_PAGE_SIZE },
     },
     useGlobalFilter,
     usePagination
@@ -80,7 +83,7 @@ const Table: React.FC<TableProps> = ({
 
   useEffect(() => {
     if (!enablePagination) {
-      setPageSize(data.length);
+      setPageSize(data.length || MIN_PAGE_SIZE);
     }
   }, [data, enablePagination]);