You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/framework/angular/guide/table-state.md
+8-9Lines changed: 8 additions & 9 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -28,8 +28,7 @@ A table instance has a few state surfaces:
28
28
29
29
-`table.baseAtoms` are the internal writable atoms created from the resolved initial state.
30
30
-`table.atoms` are readonly derived atoms exposed per registered state slice.
31
-
-`table.state` is a readonly flat proxy over the registered `table.atoms`, useful for full-state debug output.
32
-
-`table.store` is the underlying readonly flat TanStack Store. Prefer `table.atoms` or `table.state` in app code.
31
+
-`table.store` is the readonly flat TanStack Store derived by putting all of the registered `table.atoms` together.
33
32
34
33
The Angular adapter provides `angularReactivity(injector)` as the table's reactivity binding. Core readonly atoms are Angular `computed` values, writable atoms are Angular `signal` values, and subscriptions bridge through `toObservable(computed(...), { injector })`. `injectTable` reruns the options initializer when Angular signals read inside it change, then calls `table.setOptions`.
35
34
@@ -61,7 +60,7 @@ this.table.atoms.sorting.get()
61
60
// this.table.atoms.rowSelection // TypeScript error unless rowSelectionFeature is registered
62
61
```
63
62
64
-
If `features` does not include a feature, its state should not be available in `table.atoms`, `table.store.state`, `initialState`, `state`, or `atoms`.
63
+
If `features` does not include a feature, its state should not be available in `table.atoms`, `table.store.get()`, `initialState`, `state`, or `atoms`.
Atom reads are signal reads in Angular. If `this.table.atoms.pagination.get()` is used in a template expression, `computed(...)`, or `effect(...)`, Angular tracks it and updates when that atom changes.
The v8-style `onStateChange` option is no longer part of the v9 `injectTable` state model. v9 encourages keeping table state slices atomic and separated for performance.
245
+
Use the per-slice `on[State]Change` callbacks to keep controlled table state slices atomic and separated.
Copy file name to clipboardExpand all lines: docs/framework/solid/guide/table-state.md
+69-55Lines changed: 69 additions & 55 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -32,7 +32,6 @@ A table instance has a few state surfaces:
32
32
-`table.baseAtoms` are the internal writable atoms created from the resolved initial state.
33
33
-`table.atoms` are readonly derived atoms exposed per registered state slice.
34
34
-`table.store` is a readonly flat TanStack Store derived by putting all of the registered `table.atoms` together.
35
-
-`table.state()` is Solid-only selected state. It is the accessor returned from the selector passed as the second argument to `createTable`.
36
35
37
36
The Solid adapter provides `solidReactivity(owner)` to the table's `coreReativityFeature`. Core readonly atoms are Solid `createMemo` values and core writable atoms are Solid `createSignal` values. Because atom `.get()` reads through Solid signals and memos, table APIs can be consumed inside Solid computations and update only the computations that read the relevant state.
38
37
@@ -64,7 +63,7 @@ table.atoms.sorting.get()
64
63
// table.atoms.rowSelection // TypeScript error unless rowSelectionFeature is registered
65
64
```
66
65
67
-
If `features` does not include a feature, its state should not be available in `table.atoms`, `table.store.state`, `table.state()`, `initialState`, `state`, or `atoms`.
66
+
If `features` does not include a feature, its state should not be available in `table.atoms`, `table.store.get()`, `initialState`, `state`, or `atoms`.
68
67
69
68
### Accessing Table State
70
69
@@ -73,9 +72,9 @@ There are two different questions when reading table state:
73
72
- Do you only need the current value?
74
73
- Or should a Solid computation update when that value changes?
75
74
76
-
Use a direct atom or store read for the current value. Use a selector, accessor, or `table.Subscribe`when you want Solid's fine-grained updates.
75
+
Use direct atom reads for slice values. Use `table.store.get()`for the current flat state snapshot. Because Solid table atoms are backed by Solid signals and memos, atom reads participate in Solid dependency tracking when they happen inside JSX, `createMemo(...)`, `createEffect(...)`, or `table.Subscribe`.
77
76
78
-
#### Reading State Without Subscribing
77
+
#### Reading State
79
78
80
79
The simplest and most performant way to read a current state value is to read the matching atom:
You can also read the current flat store snapshot:
88
87
89
88
```tsx
90
-
const tableState =table.store.state
91
-
const pagination =table.store.state.pagination
89
+
const tableState =table.store.get()
90
+
const pagination =table.store.get().pagination
92
91
```
93
92
94
-
These reads are current-value reads. They only participate in Solid dependency tracking when they are called inside a Solid reactive scope that tracks those reads. If the UI needs to stay reactive to table state changes, use `table.state()`, `table.Subscribe`, or even a `useSelector` hook from TanStack Store.
93
+
These reads are current-value reads. They only participate in Solid dependency tracking when they are called inside a Solid reactive scope that tracks those reads. Prefer `table.atoms.<slice>.get()` for narrow reactive reads. Use `table.store.get()` for full-state debug output or when a computation intentionally depends on the whole table state.
95
94
96
-
#### Reading Reactive State with createTable
95
+
#### Reading Reactive State with Solid
97
96
98
-
The second argument to `createTable` is a TanStack Store selector. The selected value is exposed as `table.state()`. The default selector selects all registered table state.
97
+
Use Solid's native primitives to derive reactive values from table atoms or the flat store snapshot.
You can use the selected state in `createMemo`, JSX, or other Solid computations. Those computations update when the selected state changes.
119
+
You can use atom reads directly in JSX too:
120
+
121
+
```tsx
122
+
<span>
123
+
Page {table.atoms.pagination.get().pageIndex+1} of {table.getPageCount()}
124
+
</span>
125
+
```
121
126
122
127
#### Fine-grained Updates with table.Subscribe
123
128
124
-
Use `table.Subscribe` when you want a specific part of the Solid tree to subscribe to a selected table state value. The child function receives a Solid accessor.
129
+
Use `table.Subscribe` when you want a specific part of the Solid tree to create a reactive render boundary. Its child function receives `table.atoms`, and Solid tracks only the atom reads used inside that child.
125
130
126
-
Without a `source` prop, `table.Subscribe` subscribes to `table.store` and requires a selector. With a `source` prop, it can subscribe directly to one atom or store.
You should almost never need to set table state directly. TanStack Table features expose dedicated APIs for interacting with their state, and those APIs are the safest way to make changes.
@@ -232,11 +246,11 @@ Slice reset APIs like `resetPagination()` update through that feature's state up
232
246
233
247
### Controlled State
234
248
235
-
If you need easy access to table state in other parts of your application, you can control individual state slices. In v9, external atoms are the recommended way to do this because they preserve the atomic state model and Solid can update computations that read only the relevant slices.
249
+
If you need easy access to table state in other parts of your application, you can control individual state slices. In Solid, use native signals with `state` plus `on[State]Change` when you want Solid to own the slice. Use external TanStack Store atoms when you already want app-level atom sharing or direct atom subscriptions outside the table.
236
250
237
251
#### External Atoms
238
252
239
-
Use external atoms when the app should own one or more table state slices. Create stable writable atoms with `createAtom`, pass them to `atoms`, and subscribe to them with `useSelector` anywhere else in your app.
253
+
Use external atoms when the app should own one or more table state slices as TanStack Store atoms. Create stable writable atoms with `createAtom`, pass them to `atoms`, and subscribe to them with `useSelector` anywhere else in your app. `@tanstack/solid-store` is only needed by your app if you choose this pattern; the Solid table adapter itself uses Solid-native reactivity.
@@ -284,7 +298,7 @@ When using the `atoms` option for a slice, you do not need to add the matching `
284
298
285
299
#### External State
286
300
287
-
The classic `state` plus `on[State]Change`pattern is still supported. This can be convenient for simple integrations or when migrating v8 code, but it is less atomic than external atoms.
301
+
Use `state` plus `on[State]Change` when Solid signals should own a table state slice.
The v8-style `onStateChange` option is no longer part of the v9 `createTable` state model. v9 encourages keeping table state slices atomic and separated for performance.
333
+
Use the per-slice `on[State]Change` callbacks to keep controlled table state slices atomic and separated.
0 commit comments