getting-started
它能做什么
这项技能展示如何用 TanStack Table 在 React 应用中创建并显示数据表格。适合希望自己控制表格样式的 React 开发者。
适用场景
- ✓当你在构建一个显示记录表格的 React 组件的时候。
- ✓当你需要查询或虚拟滚动功能与 React 表格配合的时候。
- ✓当你的 React 应用需要根据列定义绘制表头、行和单元格的时候。
技能链接
https://github.com/TanStack/table/blob/main/packages/react-table/skills/getting-started/SKILL.md复制后粘贴给你的 AI(Claude、ChatGPT 或 Cursor),让它按照说明操作。
使用方法
最简单的方法:复制下面的消息,粘贴给你的 AI。它会读取这个技能并按说明操作。
可直接粘贴的消息
适用于 Claude Code、Codex 或 Cursor:在项目文件夹中运行,即可安装该技能。
下载 SKILL.md,放进智能体的技能文件夹。
可以这样问 AI
“我需要一个 React 表格,列出客户的姓名和年龄两列。应该如何构建?”
每周 5 个新技能,1 分钟读完。
工作原理
它展示如何用辅助函数定义列,用钩子创建表格,然后遍历表头和行来绘制表格。
技术内容(原始 SKILL.md)
作者在 GitHub 上的英文原文。
React Table setup and integration
Before starting, run intent load @tanstack/table-core#core for the shared headless model and stable-input rules.
Setup
import { useState } from 'react'
import {
createColumnHelper,
tableFeatures,
useTable,
} from '@tanstack/react-table'
type Person = { name: string; age: number }
const features = tableFeatures({})
const helper = createColumnHelper<typeof features, Person>()
const columns = helper.columns([
helper.accessor('name', { header: 'Name' }),
helper.accessor('age', { header: 'Age' }),
])
export function PeopleTable() {
const [data] = useState<Person[]>([{ name: 'Ada', age: 36 }])
const table = useTable({ features, columns, data })
return (
<table>
<thead>
{table.getHeaderGroups().map((group) => (
<tr key={group.id}>
{group.headers.map((header) => (
<th key={header.id}>
{header.isPlaceholder ? null : (
<table.FlexRender header={header} />
)}
</th>
))}
</tr>
))}
</thead>
<tbody>
{table.getRowModel().rows.map((row) => (
<tr key={row.id}>
{row.getAllCells().map((cell) => (
<td key={cell.id}>
<table.FlexRender cell={cell} />
</td>
))}
</tr>
))}
</tbody>
</table>
)
}
Table produces models and state; React owns the semantic markup, styles, event affordances, and accessibility.
Essential constraints
Use useTable for v9. Keep features, columns, and fallback data at module scope or in stable state/memos. A new response.data ?? [] fallback invalidates row models on every render. The default selector subscribes the owner to all registered state.
Table owns models and state. The application owns markup, CSS, interactions, and accessibility. Core-only tables use row.getAllCells(); visibility-aware methods need columnVisibilityFeature. Optional state and APIs require their features. Put row-model slots after their prerequisite features in tableFeatures().
Load by task
- For repeated features, defaults, typed contexts, or component registries, read reusable app hooks.
- For Query-backed data, server pages, sorting, filtering, or request keys, read TanStack Query integration.
- For virtual rows, columns, dynamic measurement, or infinite scrolling, read TanStack Virtual integration.
- For controlled state, tracked reads, or render subscriptions, read table state.
- For feature registration, missing feature APIs, or processing ownership, run
intent load @tanstack/table-core#table-featuresand read only references needed by the task. - For v8 code, read the migration checklist.
API discovery
Inspect node_modules/@tanstack/react-table/dist/index.d.ts, then the exported adapter declarations for the installed version. Inspect optional core APIs under node_modules/@tanstack/table-core/dist/features/.
常见问题
我需要先阅读核心指南吗?
这项技能要求你先阅读共享的核心指南,了解无头模型和稳定的输入规则。
为什么列应该保持稳定?
这项技能建议使用稳定的输入,使表格不会在每次渲染时重新构建模型。
它只适用于 React 吗?
是的,它涵盖 TanStack Table v9 的 React 适配器,其他框架有单独的指南。
详情
作者的原始描述
Create and render Table v9 with the react adapter. Route reusable createTableHook components, Query and Virtual integration, and framework setup; use table-state for reactive ownership.
repo: TanStack/table
热度
- GitHub 星标
- 29k
- 排名
- #9824
- 许可证
- MIT
- 更新时间
- 2026/10/21
评论
- …
同一仓库的更多技能
getting-started
29k教你的智能体如何在 Alpine.js 中使用 TanStack Table 构建并显示数据表格,涵盖设置、响应式数据和渲染行。
table-state
29k教你的智能体如何在 Alpine.js 中读取和控制表格状态,例如当前页码,使状态变化时屏幕能够更新。
devtools
29k教你的智能体如何把 Angular 表格注册到 TanStack Devtools 面板中,使开发者在构建应用时能检查每个表格。
getting-started
29k教你的智能体如何在 Angular 中创建并显示 TanStack 表格,涵盖 injectTable 设置、模板渲染和行数据的更新。