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.mdSao 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
Dành cho Claude Code, Codex hoặc Cursor: chạy lệnh trong thư mục dự án của bạn và skill sẽ được cài đặt.
Tải tệp SKILL.md về và thả vào thư mục skill của agent.
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
Bình luận
- …
Thêm skill từ kho mã này
getting-started
29kHướng dẫn agent của bạn cách tạo và hiển thị bảng dữ liệu với TanStack Table trong Alpine.js, gồm thiết lập, dữ liệu phản ứng và hiển thị các hàng.
table-state
29kHướng dẫn agent của bạn cách đọc và điều khiển trạng thái bảng trong Alpine.js, như trang hiện tại, để màn hình cập nhật khi trạng thái đó thay đổi.
devtools
29kHướng dẫn agent của bạn cách đăng ký bảng Angular với bảng điều khiển TanStack Devtools, để lập trình viên có thể kiểm tra từng bảng trong khi xây dựng ứng dụng.
getting-started
29kHướng dẫn agent của bạn cách tạo và hiển thị bảng TanStack trong Angular, gồm thiết lập injectTable, hiển thị trong template và cập nhật dữ liệu hàng.
Skill tương tự
angular-developer
280kGiúp agent của bạn viết code Angular và tư vấn cấu trúc dự án, hữu ích khi bắt đầu dự án mới hoặc cải thiện hiệu suất.
frontend-a11y
280kGiúp agent của bạn làm cho giao diện web dễ tiếp cận với mọi người. Đảm bảo website và ứng dụng hoạt động tốt với trình đọc màn hình và điều hướng bằng bàn phím.
frontend-patterns
280kGiúp agent của bạn áp dụng các mẫu hiện đại trong phát triển frontend. Tối ưu hiệu năng, quản lý trạng thái và tuân theo thực hành tốt nhất với React và Next.js.