secondsky/claude-skills / plugins/tanstack-table/skills/tanstack-table
tanstack-table
VerifiedTanStack 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.
| File | Kind | Size |
|---|---|---|
| SKILL.md | skill md | 22.1 KB |
| references/cloudflare-d1-examples.md | markdown | 3.4 KB |
| references/common-errors.md | markdown | 4.5 KB |
| references/feature-controls.md | markdown | 4.3 KB |
| references/performance-virtualization.md | markdown | 2.4 KB |
| references/query-integration.md | markdown | 5.1 KB |
| references/server-side-patterns.md | markdown | 8.9 KB |
| templates/basic-client-table.tsx | other | 2.7 KB |
| templates/column-configuration.tsx | other | 4.1 KB |
| templates/controlled-table-state.tsx | other | 9.0 KB |
| templates/d1-database-example.tsx | other | 9.2 KB |
| templates/package.json | manifest | 631 B |
| templates/server-paginated-table.tsx | other | 6.2 KB |
| templates/shadcn-styled-table.tsx | other | 3.2 KB |
| templates/virtualized-large-dataset.tsx | other | 4.7 KB |
templates/server-paginated-table.tsx
View on GitHub/**
* Server-Side Paginated Table
*
* Complete example of TanStack Table + TanStack Query for server-side pagination.
* Use for: Large datasets (1000+ rows), data from API
*/
import {
useReactTable,
getCoreRowModel,
ColumnDef,
PaginationState,
flexRender,
} from '@tanstack/react-table'
import { useQuery } from '@tanstack/react-query'
import { useState } from 'react'
interface User {
id: string
name: string
email: string
created_at: string
}
interface UsersResponse {
data: User[]
pagination: {
page: number
pageSize: number
total: number
pageCount: number
}
}
const columns: ColumnDef<User>[] = [
{
accessorKey: 'id',
header: 'ID',
size: 80,
},
{
accessorKey: 'name',
header: 'Name',
},
{
accessorKey: 'email',
header: 'Email',
},
{
accessorKey: 'created_at',
header: 'Created',
cell: info => new Date(info.getValue() as string).toLocaleDateString(),
},
]
export function ServerPaginatedTable() {
const [pagination, setPagination] = useState<PaginationState>({
pageIndex: 0,
pageSize: 20,
})
// TanStack Query: Fetch data from API
// CRITICAL: Include ALL table state in query key for proper refetching
const { data, isLoading, isError, error } = useQuery<UsersResponse>({
queryKey: ['users', pagination.pageIndex, pagination.pageSize],
queryFn: async () => {
const response = await fetch(
`/api/users?page=${pagination.pageIndex}&pageSize=${pagination.pageSize}`
)
if (!response.ok) {
throw new Error('Failed to fetch users')
}
return response.json()
},
// Keep previous data while fetching new page
placeholderData: (previousData) => previousData,
})
// TanStack Table: Manage display and interactions
const table = useReactTable({
data: data?.data ?? [],
columns,
getCoreRowModel: getCoreRowModel(),
// CRITICAL: Tell table that pagination is handled by server
manualPagination: true,
pageCount: data?.pagination.pageCount ?? 0,
state: {
pagination,
},
onPaginationChange: setPagination,
})
if (isLoading) {
return (
<div className="p-4">
<div className="animate-pulse">
<div className="h-8 bg-gray-200 rounded mb-4"></div>
<div className="space-y-3">
{[...Array(5)].map((_, i) => (
<div key={i} className="h-12 bg-gray-200 rounded"></div>
))}
</div>
</div>
</div>
)
}
if (isError) {
return (
<div className="p-4">
<div className="bg-red-50 border border-red-200 text-red-700 px-4 py-3 rounded">
Error: {error.message}
</div>
</div>
)
}
return (
<div className="p-4">
<h2 className="text-2xl font-bold mb-4">Users (Server-Side Pagination)</h2>
<div className="overflow-x-auto">
<table className="w-full border-collapse border border-gray-300">
<thead>
{table.getHeaderGroups().map(headerGroup => (
<tr key={headerGroup.id} className="bg-gray-100">
{headerGroup.headers.map(header => (
<th
key={header.id}
className="border border-gray-300 px-4 py-2 text-left font-semibold"
style={{ width: header.getSize() }}
>
{header.isPlaceholder
? null
: flexRender(
header.column.columnDef.header,
header.getContext()
)}
</th>
))}
</tr>
))}
</thead>
<tbody>
{table.getRowModel().rows.map(row => (
<tr key={row.id} className="hover:bg-gray-50">
{row.getVisibleCells().map(cell => (
<td key={cell.id} className="border border-gray-300 px-4 py-2">
{flexRender(cell.column.columnDef.cell, cell.getContext())}
</td>
))}
</tr>
))}
</tbody>
</table>
</div>
{/* Pagination Controls */}
<div className="flex items-center justify-between mt-4">
<div className="flex items-center gap-2">
<button
onClick={() => table.firstPage()}
disabled={!table.getCanPreviousPage()}
className="px-3 py-1 border rounded disabled:opacity-50 disabled:cursor-not-allowed hover:bg-gray-100"
>
{'<<'}
</button>
<button
onClick={() => table.previousPage()}
disabled={!table.getCanPreviousPage()}
className="px-3 py-1 border rounded disabled:opacity-50 disabled:cursor-not-allowed hover:bg-gray-100"
>
{'<'}
</button>
<button
onClick={() => table.nextPage()}
disabled={!table.getCanNextPage()}
className="px-3 py-1 border rounded disabled:opacity-50 disabled:cursor-not-allowed hover:bg-gray-100"
>
{'>'}
</button>
<button
onClick={() => table.lastPage()}
disabled={!table.getCanNextPage()}
className="px-3 py-1 border rounded disabled:opacity-50 disabled:cursor-not-allowed hover:bg-gray-100"
>
{'>>'}
</button>
</div>
<div className="flex items-center gap-4 text-sm">
<span>
Page <strong>{table.getState().pagination.pageIndex + 1}</strong> of{' '}
<strong>{table.getPageCount()}</strong>
</span>
<span>
Total: <strong>{data?.pagination.total ?? 0}</strong> users
</span>
<select
value={table.getState().pagination.pageSize}
onChange={e => {
table.setPageSize(Number(e.target.value))
}}
className="border rounded px-2 py-1"
>
{[10, 20, 30, 40, 50].map(pageSize => (
<option key={pageSize} value={pageSize}>
Show {pageSize}
</option>
))}
</select>
</div>
</div>
</div>
)
}
Related skills
| Skill | Stars | Updated | Works with | Status | Install |
|---|---|---|---|---|---|
| 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: 198k | Updated | Claude CodeCodex | Verified | Install |
| 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: 194k | Updated | Claude CodeCodex | Verified | Install |
| ponytail-debtDietrichGebert/ponytailHarvest every shortcut: comment into one debt ledger, so deferrals get tracked instead of forgotten. One-shot report. | Stars: 194k | Updated | Claude CodeCodex | Verified | Install |
| 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: 194k | Updated | Claude CodeCodex | Verified | Install |