Skip to content

secondsky/claude-skills / plugins/tanstack-table/skills/tanstack-table

tanstack-table

Verified

TanStack Table v8 headless data tables with server-side features for Cloudflare Workers + D1. Use for pagination, filtering, sorting, virtualization, or encountering state management, TanStack Query coordination, URL sync errors.

references/performance-virtualization.md

View on GitHub
# Performance & Virtualization

Guide to optimizing TanStack Table for large datasets using TanStack Virtual.

## When to Virtualize

- **Client-side tables with 1000+ rows**
- **Scrolling feels slow or janky**
- **Browser runs out of memory**
- **Need to render 10k+ rows efficiently**

## TanStack Virtual Basics

```bash
npm install @tanstack/react-virtual
```

```typescript
import { useVirtualizer } from '@tanstack/react-virtual'
import { useRef } from 'react'

function VirtualizedTable() {
  const containerRef = useRef<HTMLDivElement>(null)

  const rowVirtualizer = useVirtualizer({
    count: rows.length, // Total number of rows
    getScrollElement: () => containerRef.current, // Scroll container
    estimateSize: () => 50, // Estimated row height
    overscan: 10, // Extra rows to render (smooth scrolling)
  })

  return (
    <div ref={containerRef} style={{ height: '600px', overflow: 'auto' }}>
      {/* Only render visible rows */}
      {rowVirtualizer.getVirtualItems().map(virtualRow => {
        const row = rows[virtualRow.index]
        return <tr key={row.id}>{/* ... */}</tr>
      })}
    </div>
  )
}
```

## Complete Example

See `templates/virtualized-large-dataset.tsx`

## Performance Tips

### 1. Memoize Data and Columns

```typescript
// BAD: New array every render
const data = [...]

// GOOD: Stable reference
const data = useMemo(() => [...], [])
```

### 2. Use Column Sizes

```typescript
const columns = [
  { accessorKey: 'id', header: 'ID', size: 80 }, // Fixed width
  { accessorKey: 'name', header: 'Name' }, // Flexible
]
```

### 3. Avoid Heavy Cell Renderers

```typescript
// BAD: Complex logic in every cell
cell: info => <ExpensiveComponent data={info.getValue()} />

// GOOD: Memoized component
const MemoizedCell = React.memo(ExpensiveComponent)
cell: info => <MemoizedCell data={info.getValue()} />
```

### 4. Enable Row Selection Carefully

```typescript
// Only if needed - adds overhead
enableRowSelection: true,
```

### 5. Use Server-Side for Very Large Data

If dataset >10k rows, consider server-side pagination instead of virtualization.

## Measuring Performance

```typescript
import { Profiler } from 'react'

<Profiler id="Table" onRender={(id, phase, actualDuration) => {
  console.log(`${id} ${phase} took ${actualDuration}ms`)
}}>
  <MyTable />
</Profiler>
```

## Further Reading

- [TanStack Virtual Docs](https://tanstack.com/virtual/latest)
- [Complete Example](../templates/virtualized-large-dataset.tsx)
slack-gif-creatoranthropics/skillsKnowledge and utilities for creating animated GIFs optimized for Slack. Provides constraints, validation tools, and animation concepts. Use when users request animated GIFs for Slack like "make me a GIF of X doing Y for Slack."Stars: 197kUpdated Claude CodeCodexVerifiedInstall
ponytailDietrichGebert/ponytailLazy senior dev mode for any coding task: the smallest change that fully solves it, and a reply a busy human understands in one read.Stars: 194kUpdated Claude CodeCodexVerifiedInstall
ponytail-debtDietrichGebert/ponytailHarvest every shortcut: comment into one debt ledger, so deferrals get tracked instead of forgotten. One-shot report.Stars: 194kUpdated Claude CodeCodexVerifiedInstall
ponytail-debtDietrichGebert/ponytailList every `shortcut:` comment (and older `ponytail:` ones) as a debt ledger. One-shot report, changes nothing. Use for "ponytail debt", "what did ponytail defer", "list the shortcuts", /ponytail-debt.Stars: 194kUpdated Claude CodeCodexVerifiedInstall