From 044cf2e10939186c4e6c2929603b2f4f3baca740 Mon Sep 17 00:00:00 2001 From: Ruben Folhento <9657174+kingdevil731@users.noreply.github.com> Date: Fri, 12 Apr 2024 16:53:42 +0200 Subject: [PATCH] Update TableSort.tsx The keys(data[0]) operation is performed for each item in the data array. This is inefficient, as the keys are the same for all items. It is better to perform this operation once and reuse the result. --- lib/TableSort/TableSort.tsx | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lib/TableSort/TableSort.tsx b/lib/TableSort/TableSort.tsx index 08294cc8..231a8615 100644 --- a/lib/TableSort/TableSort.tsx +++ b/lib/TableSort/TableSort.tsx @@ -46,8 +46,9 @@ function Th({ children, reversed, sorted, onSort }: ThProps) { function filterData(data: RowData[], search: string) { const query = search.toLowerCase().trim(); + const firstDataItemKeys = keys(data[0]); return data.filter((item) => - keys(data[0]).some((key) => item[key].toLowerCase().includes(query)) + firstDataItemKeys.some((key) => item[key].toLowerCase().includes(query)) ); }