跳到正文
Skillpedia
网站与界面(前端)29k · #9818

table-state

它能做什么

这项技能解释如何把表格设置,例如当前页,保存在 Octane 状态中并显示在屏幕上。适合需要表格与页面保持同步的开发者。

适用场景

  • ✓当页面按钮必须显示当前表格页并在点击时更新它的时候。
  • ✓当你需要把 Octane 状态中的表格设置传入表格的时候。
  • ✓当表格中的值变化后,在屏幕上没有刷新的时候。

技能链接

https://github.com/TanStack/table/blob/main/packages/octane-table/skills/table-state/SKILL.md

复制后粘贴给你的 AI(Claude、ChatGPT 或 Cursor),让它按照说明操作。

使用方法

最简单的方法:复制下面的消息,粘贴给你的 AI。它会读取这个技能并按说明操作。

可直接粘贴的消息

请用这个技能帮我:https://github.com/TanStack/table/blob/main/packages/octane-table/skills/table-state/SKILL.md 阅读该链接中的 SKILL.md 文件,并在我的任务中按照它的说明来做。
想让你的 AI 自己找到这样的技能吗?安装免费的 Skillpedia MCP:只需一行,每次任务前它都会在 15,000+ 个技能中搜索。1 分钟完成安装 →

可以这样问 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.
  • useTable stages 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-store is a direct synchronous owner. Table writes reach it immediately; it takes precedence over controlled state for 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

这个技能有用吗?

0

登录 后即可投票。

评论

  • …

同一仓库的更多技能

相似技能