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

table-state

它能做什么

这项技能解释如何决定表格状态的每个部分,例如分页,由表格还是你自己的代码控制。适合需要表格与应用就这些值达成一致的开发者。

适用场景

  • ✓当你想设置表格的起始状态,例如每页数量,而不想完全接管它的时候。
  • ✓当你需要自己控制某个状态片段,并把它的变化反馈给表格的时候。
  • ✓当表格状态的变化没有按你预期的方式保留或重置的时候。

技能链接

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

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

使用方法

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

可直接粘贴的消息

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

可以这样问 AI

“如何让我的表格以每页 25 条开始,同时仍然允许它自行切换页面?”

每周 5 个新技能,1 分钟读完。

工作原理

它展示如何为表格拥有的片段设置初始值,受控片段如何同时获得值和变化回调,以及如何用表格自带的函数重置状态。

技术内容(原始 SKILL.md)

作者在 GitHub 上的英文原文。

Shared table state

Read core first for stable model inputs and feature-gated types. State repair in an existing table can start here without adapter setup guidance.

Start with internal ownership

Omit state, atoms, and on<Slice>Change for slices that Table should own. Use initialState only to customize their initial values.

<!-- skill-snippet:check -->
import {
  constructTable,
  createColumnHelper,
  rowPaginationFeature,
  tableFeatures,
} from '@tanstack/table-core'
import { storeReactivityBindings } from '@tanstack/table-core/store-reactivity-bindings'

type Person = { id: string; name: string }
const features = tableFeatures({
  coreReactivityFeature: storeReactivityBindings(),
  rowPaginationFeature,
})
const helper = createColumnHelper<typeof features, Person>()
const columns = helper.columns([helper.accessor('name', {})])
const data: Person[] = [{ id: '1', name: 'Ada' }]
const table = constructTable({
  features,
  columns,
  data,
  initialState: { pagination: { pageIndex: 0, pageSize: 25 } },
})
table.setPageSize(50)
console.log(table.atoms.pagination.get().pageSize)
table.resetPagination()
console.log(table.atoms.pagination.get().pageSize)

This example demonstrates state only. A pagination row-model slot is needed when Table should also slice the data.

Choose one owner per slice

Owner Configuration Update path
Table Omit external values; optionally provide initialState.<slice> Feature setter or interaction handler
Framework state Current state.<slice> plus matching on<Slice>Change Callback applies the updater and the adapter receives the fresh value
External atom Stable writable atoms.<slice> Feature setters write directly to that atom; no matching callback is needed

Prefer the smallest set of externally owned slices. Load the adapter's table-state skill before selecting framework state or an external atom package. Native signals, runes, refs, tracked properties, and Store atoms have different adapter wiring.

An updater can be a value or a function of the previous value. In a custom callback, use functionalUpdate(updater, previousValue) from @tanstack/table-core and write the result to the owner. Supplying only on<Slice>Change replaces the internal updater without returning a current controlled value; supplying only state.<slice> leaves no effective external update path.

If both atoms.<slice> and state.<slice> are supplied, the external atom wins. Choose one owner deliberately; writing an internal base atom cannot change a slice resolved from an external atom.

Distinguish state reads and writes

  • table.baseAtoms contains internal writable atoms created from resolved initial state. Prefer feature setters; direct base-atom writes bypass feature-specific behavior.
  • table.atoms contains readonly resolved atoms per registered slice. table.atoms.pagination.get() reads whichever owner supplies pagination.
  • table.store is the readonly flat combination of resolved slices. table.store.state reads its current snapshot.
  • table.state, where an adapter exposes it, is adapter-selected state. Its presence and subscription behavior are not shared core contracts.

A feature must be registered before its state appears in initialState, state, atoms, baseAtoms, or store. Let the concrete feature registry infer TableState; import a slice type such as PaginationState for an external owner instead of widening the complete state.

A direct atom/store read is not a portable framework subscription. Its tracking depends on the adapter and the scope of the read. For reactive UI, load intent load <package>#table-state using the installed adapter package, for example intent load @tanstack/react-table#table-state. Use that skill's supported read and subscription APIs.

Initialization and resets

initialState resolves at construction. Changing the supplied object later does not reset the table. Keep the registered features and external atom identities stable for the instance lifetime.

Feature resets such as `r

常见问题

我必须总是自己控制状态吗?

不必,这项技能说明对于应由表格拥有的片段应省略状态,而 initialState 只用于起始值。

一个状态片段可以有两个所有者吗?

不可以,这项技能说明每个片段应只选择一个所有者。

这项技能涵盖每个框架中的响应式读取吗?

不涵盖,它涵盖共享的所有权规则,并把响应式读取指向适配器的状态技能。

详情

作者的原始描述

Choose Table v9 state ownership, atoms, initialization, updates, and resets. Load for controlled slices or state coordination; use the adapter state skill for reactive reads.

repo: TanStack/table

热度

GitHub 星标
29k
排名
#9838
许可证
MIT
更新时间
2026/10/21

这个技能有用吗?

0

登录 后即可投票。

评论

  • …

同一仓库的更多技能

相似技能