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

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 một component Preact và cách bảng đọc chúng. Skill dành cho lập trình viên Preact cần giao diện khớp với trạng thái của bảng.

Khi nào nên dùng

  • ✓Khi một component Preact phải 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 bảng từ component vào bảng.
  • ✓Khi giao diện Preact không cập nhật sau khi một thiết lập bảng thay đổi.

Liên kết skill

https://github.com/TanStack/table/blob/main/packages/preact-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/preact-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 Preact sau khi nút trang tiếp theo được bấm?”

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 một hook state, truyền nó cho bảng cùng một callback cập nhật tương ứng, và đọc trạng thái được 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.

Preact 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 Preact subscriptions.

Use selected table.state in the owner render. For narrower boundaries, use table.Subscribe or useSelector from @tanstack/preact-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 'preact/hooks'
import {
  rowPaginationFeature,
  tableFeatures,
  useTable,
  type PaginationState,
} from '@tanstack/preact-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 Preact 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/preact-store, pass it in atoms.<slice>, and subscribe with useSelector where other UI needs its value.

Reactive boundaries

Use native @tanstack/preact-store bindings. A narrowed selector must include every state slice used by rendered builder methods, or those consumers need their own subscription.

For external-atom examples, selector dependencies, or fine-grained boundaries, 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/preact-table/dist/useTable.d.ts and Subscribe.d.ts, plus the installed @tanstack/preact-store declarations for atom hooks.

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

Vì sao đọc một giá trị trong trình xử lý click không làm mới giao diện?

Giá trị đọc trong trình xử lý là bản chụp nhanh tại thời điểm đó, nên giao diện chỉ làm mới từ trạng thái được chọn hoặc một subscription.

Tôi có cần truyền callback cùng với giá trị không?

Có. Skill yêu cầu ghép mỗi giá trị được điều khiển với callback của nó để thay đổi được truyền ngược lại component.

Tôi có thể giới hạn phần nào của bảng được render lại không?

Có. Hướng dẫn mô tả các subscription hẹp hơn, nhưng khuyên dùng mặc định cho đến khi chi phí render khiến việc thu hẹp đáng làm.

Chi tiết

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

Read and control Table v9 state in preact. 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
#9822
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ự