Skip to content

fix(react): table sorting example delay #993

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions examples/react/table/src/main.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,13 @@ import {
useReactTable,
} from '@tanstack/react-table'
import { makeData } from './makeData'
import type { ColumnDef, Row, SortingState } from '@tanstack/react-table'
import type { ColumnDef, SortingState } from '@tanstack/react-table'
import type { Person } from './makeData'
import './index.css'

function ReactTableVirtualized() {
const [sorting, setSorting] = React.useState<SortingState>([])
const [_sorting, setSorting] = React.useState<SortingState>([])
const sorting = React.useDeferredValue(_sorting);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@giuliobracci Hmm, virtualized tables already improve performance by only rendering visible rows. I'm a bit concerned this might give the impression that useDeferredValue is needed in most cases, which isn't really true.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @piecyk you can try the diff with the example.
To me through stackblitz it seems that the lag is very noticeable when applying sorting.


const columns = React.useMemo<Array<ColumnDef<Person>>>(
() => [
Expand Down Expand Up @@ -61,7 +62,7 @@ function ReactTableVirtualized() {
[],
)

const [data, setData] = React.useState(() => makeData(50_000))
const [data] = React.useState(() => makeData(50_000))

const table = useReactTable({
data,
Expand Down