@tanstack/preact-table 9.0.0-alpha.47 → 9.0.0-alpha.48
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +10 -0
- package/package.json +6 -4
- package/skills/preact/client-to-server/SKILL.md +294 -0
- package/skills/preact/compose-with-tanstack-form/SKILL.md +230 -0
- package/skills/preact/compose-with-tanstack-pacer/SKILL.md +186 -0
- package/skills/preact/compose-with-tanstack-query/SKILL.md +283 -0
- package/skills/preact/compose-with-tanstack-store/SKILL.md +263 -0
- package/skills/preact/compose-with-tanstack-virtual/SKILL.md +275 -0
- package/skills/preact/getting-started/SKILL.md +371 -0
- package/skills/preact/migrate-v8-to-v9/SKILL.md +322 -0
- package/skills/preact/production-readiness/SKILL.md +278 -0
- package/skills/preact/table-state/SKILL.md +432 -0
- package/skills/preact/table-state/references/advanced-state-patterns.md +93 -0
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
# Advanced state patterns — Preact
|
|
2
|
+
|
|
3
|
+
Extended state patterns extracted from `SKILL.md`. The three essential patterns (`useTable` selector, `<table.Subscribe>` walls, and external atoms via `useCreateAtom` + `options.atoms`) remain inline in the SKILL; this file covers the additional patterns.
|
|
4
|
+
|
|
5
|
+
## External state with `state` + `on*Change`
|
|
6
|
+
|
|
7
|
+
Classic Preact `useState` integration is still supported via `state` and matching `on[State]Change`. Useful for v8 migration paths or simple cases. Less fine-grained than external atoms.
|
|
8
|
+
|
|
9
|
+
```tsx
|
|
10
|
+
const [sorting, setSorting] = useState<SortingState>([])
|
|
11
|
+
const [pagination, setPagination] = useState<PaginationState>({
|
|
12
|
+
pageIndex: 0,
|
|
13
|
+
pageSize: 10,
|
|
14
|
+
})
|
|
15
|
+
|
|
16
|
+
const table = useTable({
|
|
17
|
+
_features,
|
|
18
|
+
_rowModels: {
|
|
19
|
+
/* … */
|
|
20
|
+
},
|
|
21
|
+
columns,
|
|
22
|
+
data,
|
|
23
|
+
state: { sorting, pagination },
|
|
24
|
+
onSortingChange: setSorting,
|
|
25
|
+
onPaginationChange: setPagination,
|
|
26
|
+
})
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
Source: `docs/framework/preact/guide/table-state.md`.
|
|
30
|
+
|
|
31
|
+
## `createTableHook` for reusable shared config
|
|
32
|
+
|
|
33
|
+
When you ship the same `_features` / `_rowModels` / cell components across many tables, package them with `createTableHook`. You get `useAppTable`, `createAppColumnHelper`, `useTableContext` / `useCellContext` / `useHeaderContext`, and `table.AppTable` / `AppHeader` / `AppCell` / `AppFooter` boundaries.
|
|
34
|
+
|
|
35
|
+
```tsx
|
|
36
|
+
import {
|
|
37
|
+
createTableHook,
|
|
38
|
+
rowPaginationFeature,
|
|
39
|
+
rowSortingFeature,
|
|
40
|
+
createPaginatedRowModel,
|
|
41
|
+
createSortedRowModel,
|
|
42
|
+
sortFns,
|
|
43
|
+
tableFeatures,
|
|
44
|
+
} from '@tanstack/preact-table'
|
|
45
|
+
|
|
46
|
+
export const {
|
|
47
|
+
useAppTable,
|
|
48
|
+
createAppColumnHelper,
|
|
49
|
+
useTableContext,
|
|
50
|
+
useCellContext,
|
|
51
|
+
useHeaderContext,
|
|
52
|
+
} = createTableHook({
|
|
53
|
+
_features: tableFeatures({ rowPaginationFeature, rowSortingFeature }),
|
|
54
|
+
_rowModels: {
|
|
55
|
+
paginatedRowModel: createPaginatedRowModel(),
|
|
56
|
+
sortedRowModel: createSortedRowModel(sortFns),
|
|
57
|
+
},
|
|
58
|
+
tableComponents: { PaginationControls, RowCount },
|
|
59
|
+
cellComponents: { TextCell, NumberCell },
|
|
60
|
+
headerComponents: { SortIndicator },
|
|
61
|
+
})
|
|
62
|
+
|
|
63
|
+
const columnHelper = createAppColumnHelper<Person>()
|
|
64
|
+
|
|
65
|
+
function UsersTable({ data }: { data: Person[] }) {
|
|
66
|
+
const table = useAppTable({ columns, data })
|
|
67
|
+
|
|
68
|
+
return (
|
|
69
|
+
<table.AppTable>
|
|
70
|
+
<table>
|
|
71
|
+
<tbody>
|
|
72
|
+
{table.getRowModel().rows.map((row) => (
|
|
73
|
+
<tr key={row.id}>
|
|
74
|
+
{row.getAllCells().map((c) => (
|
|
75
|
+
<table.AppCell cell={c} key={c.id}>
|
|
76
|
+
{(cell) => (
|
|
77
|
+
<td>
|
|
78
|
+
<cell.TextCell />
|
|
79
|
+
</td>
|
|
80
|
+
)}
|
|
81
|
+
</table.AppCell>
|
|
82
|
+
))}
|
|
83
|
+
</tr>
|
|
84
|
+
))}
|
|
85
|
+
</tbody>
|
|
86
|
+
</table>
|
|
87
|
+
<table.PaginationControls />
|
|
88
|
+
</table.AppTable>
|
|
89
|
+
)
|
|
90
|
+
}
|
|
91
|
+
```
|
|
92
|
+
|
|
93
|
+
Source: `docs/framework/preact/guide/create-table-hook.md`; `examples/preact/basic-use-app-table/src/main.tsx`; `packages/preact-table/src/createTableHook.tsx`.
|