Chuyển đến nội dung
Skillpedia
Website và giao diện (frontend)29k · #9826

table-state

Skill này làm gì

Skill này giải thích cách giữ các thiết lập của bảng, như trang hiện tại, trong state React và cách bảng đọc chúng. Skill dành cho lập trình viên React cần giao diện khớp với state của bảng.

Khi nào nên dùng

  • ✓Khi một component React cần hiển thị trang hiện tại hoặc một thiết lập khác của bảng.
  • ✓Khi bạn cần truyền một thiết lập của bảng từ component của mình vào bảng.
  • ✓Khi giao diện React không cập nhật sau khi một thiết lập của bảng thay đổi.

Liên kết skill

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

Sao chép rồi dán vào AI của bạn (Claude, ChatGPT hoặc Cursor) và nhờ nó làm theo hướng dẫn.

Cách dùng

Cách dễ nhất: sao chép tin nhắn và dán vào AI của bạn. AI sẽ đọc skill và làm theo hướng dẫn.

Tin nhắn có sẵn để dán

Hãy dùng skill này để giúp tôi: https://github.com/TanStack/table/blob/main/packages/react-table/skills/table-state/SKILL.md Đọc tệp SKILL.md tại liên kết đó và làm theo hướng dẫn cho việc của tôi.
Bạn muốn AI tự tìm những skill như thế này?Cài MCP Skillpedia miễn phí: chỉ một dòng, và AI sẽ tìm trong 15.000+ skill trước mỗi việc.Cài đặt trong 1 phút →

Ví dụ cách nhờ AI

“Làm sao để cập nhật số trang trong bảng React của tôi sau khi tôi bấm nút sang trang tiếp theo?”

5 skill mới mỗi tuần. Đọc chỉ 1 phút.

Cách hoạt động

Skill chỉ cách lưu thiết lập bằng hook state của React, truyền nó cho bảng cùng callback cập nhật tương ứng và đọc state đã chọn để giao diện render lại.

Nội dung kỹ thuật (SKILL.md gốc)

Lấy nguyên văn từ GitHub, do tác giả viết bằng tiếng Anh.

React table state

Before starting, run intent load @tanstack/table-core#table-state for shared ownership, initialization, updates, and resets. State repair does not require loading setup guidance.

Read reactive state

useTable selects all registered state by default. Its optional second-argument selector controls rerenders and the shape of table.state. table.atoms.<slice>.get() and table.store.state are current snapshots, not React subscriptions.

Use selected table.state in the owner render. For narrower boundaries, use table.Subscribe or useSelector from @tanstack/react-store. Without source, table.Subscribe selects from table.store; with source, it subscribes to that atom or store. Start with the default selector until render cost requires narrowing.

Control a slice

Keep features, columns, and data stable. Register the feature that owns the controlled slice. This example controls pagination without adding client row processing:

import { useState } from 'react'
import {
  rowPaginationFeature,
  tableFeatures,
  useTable,
  type PaginationState,
} from '@tanstack/react-table'

const features = tableFeatures({ rowPaginationFeature })
const columns = [{ accessorKey: 'name' }]
const data = [{ name: 'Ada' }]

export function PageControl() {
  const [pagination, setPagination] = useState<PaginationState>({
    pageIndex: 0,
    pageSize: 20,
  })
  const table = useTable({
    features,
    columns,
    data,
    state: { pagination },
    onPaginationChange: setPagination,
  })
  return (
    <button onClick={() => table.setPageSize(50)}>
      {table.state.pagination.pageSize} rows per page
    </button>
  )
}

The React setter accepts both a value and a functional updater. Supply the current state.pagination together with onPaginationChange; a callback alone does not keep the table synchronized.

For an externally owned atom, create it with useCreateAtom from @tanstack/react-store, pass it in atoms.<slice>, and subscribe with useSelector where other UI needs its value.

Reactive boundaries

For React Compiler memoized children, put Subscribe inside the component hiding builder-method reads or pass the selected value as a changing prop. An outer subscription that ignores its value cannot refresh a stable child. In core-typed cell/header contexts, import standalone Subscribe.

For external-atom examples, selector dependencies, or fine-grained boundaries and React Compiler problems, read reactivity details. If this task changes processing features, run intent load @tanstack/table-core#table-features and read the relevant feature references.

API discovery

Inspect node_modules/@tanstack/react-table/dist/useTable.d.ts and Subscribe.d.ts, plus the installed @tanstack/react-store declarations for atom hooks.

Câu hỏi thường gặp

Vì sao giá trị đọc trong event handler có vẻ đã cũ?

Giá trị đọc trong handler là một bản chụp tại thời điểm đó, nên giao diện chỉ cập nhật từ state đã chọn hoặc từ một subscription.

Tôi có cần cả giá trị lẫn callback không?

Có. Skill nói nên truyền mỗi giá trị được điều khiển cùng callback cập nhật của nó để các thay đổi quay lại đúng cách.

Tôi có thể thu hẹp phần render lại không?

Được. Có các subscription hẹp hơn, nhưng skill khuyên dùng mặc định cho đến khi chi phí render buộc phải thu hẹp.

Chi tiết

Mô tả gốc của tác giả

Read and control Table v9 state in react. Use for tracked reads, subscriptions, controlled slices, and framework-specific reactive boundaries.

repo: TanStack/table

Độ phổ biến

Sao GitHub
29k
Vị trí xếp hạng
#9826
Giấy phép
MIT
Cập nhật
21/10/2026

Skill này có hữu ích không?

0

Đăng nhập để bình chọn.

Bình luận

  • …

Thêm skill từ kho mã này

Skill tương tự