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

custom-features

它能做什么

这项技能展示如何构建可复用的功能,即插件,为 TanStack Table 添加新的状态或行为。适合内置功能无法覆盖其需求的高级开发者。

适用场景

  • ✓当你需要添加可复用的状态或行为到表格对象中的时候。
  • ✓当内置选项和类型化元数据无法处理你的渲染器或应用设置的时候。
  • ✓当你编写的插件必须正确注册生命周期钩子和表格方法的时候。

技能链接

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

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

使用方法

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

可直接粘贴的消息

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

可以这样问 AI

“TanStack Table 的内置功能无法满足我的需求。我该如何编写自己的插件?”

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

工作原理

它会逐步讲解:声明该功能、保留用户状态、在生命周期钩子中添加表格和对象方法,并用稳定的功能对象注册插件。

技术内容(原始 SKILL.md)

作者在 GitHub 上的英文原文。

Author a custom feature

Read core and feature architecture first. Use a plugin for reusable state or behavior that must augment Table objects. Built-in options and typed tableMeta/columnMeta are usually enough for renderer callbacks and application configuration.

Implementation workflow

  1. Identify the state, options, and object methods the behavior owns. If it only passes callbacks or renderer data, read scoped meta typing and use meta instead.
  2. Before declaring plugin types or writing lifecycle hooks, read the complete plugin example. It enumerates all 10 public FeatureMaps, the API assignment helpers, lifecycle ordering, and the advanced row-model maps.
  3. Declare the feature key in Plugins. Merge only FeatureMaps with matching runtime implementations; declarations alone install no behavior.
  4. Preserve user state after defaults in getInitialState; connect state updaters in default options. Install table methods with assignTableAPIs and object methods with assignPrototypeAPIs inside the corresponding lifecycle hooks.
  5. Keep the feature object and tableFeatures({ customFeature }) result stable. Register the plugin through tableFeatures so inference and composition include it.
  6. Verify the advertised state, options, methods, and resets on a constructed table. Each declared API must exist at runtime; reset behavior must respect the state owner.

Lifecycle boundaries

Use initTableInstanceData for mutable data owned by one table and resetTableInstanceData for clearing its transient contents. All feature initialization finishes before any constructTableAPIs hook. Keep method installation separate from data allocation.

Prototype methods are shared across the table's rows, columns, cells, or headers. Read per-object values through the method's current instance, and use the supported instance-data hooks for mutable fields. Read the example's installation rules before adding memoized methods or advanced row-model/cache wiring.

Common failures

  • Types without matching runtime hooks advertise APIs that do not exist.
  • Ad hoc mutation of constructed instances bypasses feature registration and inferred composition.
  • Treating the density example as the only extension pattern misses column definitions and the other public FeatureMaps. Choose the maps required by the behavior; advanced row-model declarations also require runtime pipeline/cache wiring.

Installed API discovery

Inspect node_modules/@tanstack/table-core/dist/types/TableFeatures.d.ts, the exported *_FeatureMap interfaces in dist/types/, and assignTableAPIs/assignPrototypeAPIs in dist/utils.d.ts. Follow declarations under dist/features/ for comparable stock lifecycle signatures.

常见问题

什么时候不应该编写自定义功能?

这项技能说明,如果某个行为只是传递回调或渲染器数据,你应改用类型化元数据。

声明功能类型会安装它的行为吗?

不会,这项技能说明仅有声明不会安装任何东西,运行时的实现必须与声明的类型一致。

插件应该在哪里注册?

通过 tableFeatures 调用注册,这样类型推断和组合才会包含它。

详情

作者的原始描述

Implement a Table v9 plugin when built-ins and typed meta are insufficient. Covers FeatureMaps, runtime lifecycle hooks, prototypes, and a complete checked example.

repo: TanStack/table

热度

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

这个技能有用吗?

0

登录 后即可投票。

评论

  • …

同一仓库的更多技能

相似技能