table-state
它能做什么
这项技能解释如何把表格设置,例如当前页,保存在 Octane 状态中并显示在屏幕上。适合需要表格与页面保持同步的开发者。
适用场景
- ✓当页面按钮必须显示当前表格页并在点击时更新它的时候。
- ✓当你需要把 Octane 状态中的表格设置传入表格的时候。
- ✓当表格中的值变化后,在屏幕上没有刷新的时候。
技能链接
https://github.com/TanStack/table/blob/main/packages/octane-table/skills/table-state/SKILL.md复制后粘贴给你的 AI(Claude、ChatGPT 或 Cursor),让它按照说明操作。
使用方法
最简单的方法:复制下面的消息,粘贴给你的 AI。它会读取这个技能并按说明操作。
可直接粘贴的消息
适用于 Claude Code、Codex 或 Cursor:在项目文件夹中运行,即可安装该技能。
下载 SKILL.md,放进智能体的技能文件夹。
可以这样问 AI
“点击“下一页”时,如何让我的 Octane 表格的页码在屏幕上保持最新?”
每周 5 个新技能,1 分钟读完。
工作原理
它展示如何把设置保存在 Octane 状态中,将值及其设置函数一并传给表格,并在标记中读取所选状态。
技术内容(原始 SKILL.md)
作者在 GitHub 上的英文原文。
Load intent load @tanstack/table-core#table-state first for shared ownership, initialization, updater, and reset rules.
useTable selects all registered state by default. Its second argument changes the selected shape exposed as table.state and shallow-gates owner rerenders. Atom .get() and table.store.state reads are snapshots; use selected state or a rendered table.Subscribe to update the UI.
Controlled slice setup
import { useState } from 'octane'
import {
rowPaginationFeature,
tableFeatures,
useTable,
} from '@tanstack/octane-table'
const features = tableFeatures({ rowPaginationFeature })
const columns = [{ accessorKey: 'name' }]
const data = [{ name: 'Ada' }]
function PageStatus() @{
const [pagination, setPagination] = useState({ pageIndex: 0, pageSize: 20 })
const table = useTable({
features,
columns,
data,
state: { pagination },
onPaginationChange: setPagination,
})
<button onClick={() => table.nextPage()}>
Page {String(table.state.pagination.pageIndex + 1)}
</button>
}
Reactive boundaries
- Pass both the controlled value and its callback. Octane setters accept Table's value-or-updater callbacks; a callback alone cannot feed the new value back.
- Render
<table.Subscribe>as a component. Calling it as a normal function shares the owner's compiler slots instead of creating an independent hook scope. useTablestages fresh options for same-render reads. Controlled state reaches the store only from an accepted layout commit, so abandoned work cannot publish speculative values.- A stable atom from
@tanstack/octane-storeis a direct synchronous owner. Table writes reach it immediately; it takes precedence over controlledstatefor the same slice. - Keep features, columns, and data stable. Use the default selector until render cost justifies narrower subscriptions.
Read for the task
For advanced reactive boundaries, shared atoms, or detailed subscription examples, read reactivity. For construction or rendering setup, read getting-started.
API discovery
Inspect node_modules/@tanstack/octane-table/src/index.d.ts, the matching *.tsrx.d.ts sidecar, and src/types.ts. This package publishes authored source; core APIs are in installed @tanstack/table-core/dist/.
常见问题
为什么用 get() 读取值时屏幕不更新?
这些读取只是快照,因此屏幕只能通过所选状态或渲染的订阅组件更新。
设置函数可以接受更新函数吗?
可以,Octane 的设置函数接受表格使用的值或更新函数回调。
要保持状态同步,我必须传入什么?
必须同时传入受控值及其回调,因为仅有回调无法把新值反馈回来。
详情
作者的原始描述
Read and control Table v9 state in octane. Use for tracked reads, subscriptions, controlled slices, and framework-specific reactive boundaries.
repo: TanStack/table
热度
- GitHub 星标
- 29k
- 排名
- #9818
- 许可证
- 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 设置、模板渲染和行数据的更新。