From 2acd98370dd15f573345dca2e9dd47f2934d2160 Mon Sep 17 00:00:00 2001 From: Sammy Teillet Date: Mon, 24 Apr 2023 14:46:39 +0200 Subject: [PATCH] bugfix: remove infinite renderloop of onSortUpdate --- .../table/table-header/TableHeader.tsx | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/front/src/components/table/table-header/TableHeader.tsx b/front/src/components/table/table-header/TableHeader.tsx index dca266985..0510a56aa 100644 --- a/front/src/components/table/table-header/TableHeader.tsx +++ b/front/src/components/table/table-header/TableHeader.tsx @@ -3,7 +3,7 @@ import { FontAwesomeIcon } from '@fortawesome/react-fontawesome'; import DropdownButton from './DropdownButton'; import { IconProp } from '@fortawesome/fontawesome-svg-core'; import SortAndFilterBar, { SortType } from './SortAndFilterBar'; -import { useEffect, useState } from 'react'; +import { useState } from 'react'; type OwnProps = { viewName: string; @@ -53,21 +53,22 @@ function TableHeader({ const [sorts, setSorts] = useState([] as Array); const onSortItemSelect = (sortId: string) => { - setSorts([ + const newSorts = [ { label: 'Created at', order: 'asc', id: sortId, } as SortType, - ]); - }; - const onSortItemUnSelect = (sortId: string) => { - setSorts([]); + ]; + setSorts(newSorts); + onSortsUpdate && onSortsUpdate(newSorts); }; - useEffect(() => { - onSortsUpdate && onSortsUpdate(sorts); - }, [sorts, onSortsUpdate]); + const onSortItemUnSelect = (sortId: string) => { + const newSorts = [] as SortType[]; + setSorts(newSorts); + onSortsUpdate && onSortsUpdate(newSorts); + }; return (