Skip to content
This repository was archived by the owner on Jan 15, 2025. It is now read-only.

Commit 688a6e9

Browse files
committed
refactor: reduced redundant calls to column.getIsSorted()
1 parent 2ad2507 commit 688a6e9

File tree

3 files changed

+15
-9
lines changed

3 files changed

+15
-9
lines changed

packages/ui/CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
# @codefixlabs/ui
22

3+
## 0.1.28
4+
5+
### Patch Changes
6+
7+
- Reduced redundant calls to `column.getIsSorted()`
8+
39
## 0.1.27
410

511
### Patch Changes

packages/ui/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@codefixlabs/ui",
3-
"version": "0.1.27",
3+
"version": "0.1.28",
44
"license": "MIT",
55
"exports": {
66
"./package.json": "./package.json",

packages/ui/src/react/data-table.tsx

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ import {
3232
} from 'lucide-react';
3333
import pluralize from 'pluralize';
3434
import * as React from 'react';
35-
import { useId, useMemo } from 'react';
35+
import { useId } from 'react';
3636
import { twMerge } from 'tailwind-merge';
3737
import { useDebouncedCallback } from 'use-debounce';
3838
import { Badge } from '@/react/badge';
@@ -104,24 +104,24 @@ export function DataTableColumnHeader<TData, TValue>({
104104
column: Column<TData, TValue>;
105105
title: string;
106106
}): React.JSX.Element {
107-
const endIcon = useMemo(() => {
108-
if (column.getIsSorted() === 'desc') {
109-
return <ArrowDownIcon className="h-4 w-4" />;
110-
}
107+
const endIcon = (): React.JSX.Element => {
108+
const isSorted = column.getIsSorted();
111109

112-
if (column.getIsSorted() === 'asc') {
110+
if (isSorted === 'desc') {
111+
return <ArrowDownIcon className="h-4 w-4" />;
112+
} else if (isSorted === 'asc') {
113113
return <ArrowUpIcon className="h-4 w-4" />;
114114
}
115115

116116
return <ChevronsUpDownIcon className="h-4 w-4" />;
117-
}, [column]);
117+
};
118118

119119
return (
120120
<DropdownMenu>
121121
<DropdownMenuTrigger asChild>
122122
<Button
123123
className="data-state-open:bg-accent -ml-4"
124-
endIcon={endIcon}
124+
endIcon={endIcon()}
125125
size="sm"
126126
variant="ghost"
127127
>

0 commit comments

Comments
 (0)