@tanstack/react-db 0.1.81 → 0.1.83
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/package.json +3 -3
- package/skills/react-db/SKILL.md +66 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tanstack/react-db",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.83",
|
|
4
4
|
"description": "React integration for @tanstack/db",
|
|
5
5
|
"author": "Kyle Mathews",
|
|
6
6
|
"license": "MIT",
|
|
@@ -41,13 +41,13 @@
|
|
|
41
41
|
],
|
|
42
42
|
"dependencies": {
|
|
43
43
|
"use-sync-external-store": "^1.6.0",
|
|
44
|
-
"@tanstack/db": "0.6.
|
|
44
|
+
"@tanstack/db": "0.6.5"
|
|
45
45
|
},
|
|
46
46
|
"peerDependencies": {
|
|
47
47
|
"react": ">=16.8.0"
|
|
48
48
|
},
|
|
49
49
|
"devDependencies": {
|
|
50
|
-
"@electric-sql/client": "^1.5.
|
|
50
|
+
"@electric-sql/client": "^1.5.15",
|
|
51
51
|
"@testing-library/react": "^16.3.2",
|
|
52
52
|
"@types/react": "^19.2.13",
|
|
53
53
|
"@types/react-dom": "^19.2.3",
|
package/skills/react-db/SKILL.md
CHANGED
|
@@ -168,6 +168,72 @@ const mutate = usePacedMutations({
|
|
|
168
168
|
<textarea onChange={(e) => mutate(e.target.value)} />
|
|
169
169
|
```
|
|
170
170
|
|
|
171
|
+
## Includes (Hierarchical Data)
|
|
172
|
+
|
|
173
|
+
When a query uses includes (subqueries in `select`), each child field is a live `Collection` by default. Subscribe to it with `useLiveQuery` in a subcomponent:
|
|
174
|
+
|
|
175
|
+
```tsx
|
|
176
|
+
function ProjectList() {
|
|
177
|
+
const { data: projects } = useLiveQuery((q) =>
|
|
178
|
+
q.from({ p: projectsCollection }).select(({ p }) => ({
|
|
179
|
+
id: p.id,
|
|
180
|
+
name: p.name,
|
|
181
|
+
issues: q
|
|
182
|
+
.from({ i: issuesCollection })
|
|
183
|
+
.where(({ i }) => eq(i.projectId, p.id))
|
|
184
|
+
.select(({ i }) => ({ id: i.id, title: i.title })),
|
|
185
|
+
})),
|
|
186
|
+
)
|
|
187
|
+
|
|
188
|
+
return (
|
|
189
|
+
<ul>
|
|
190
|
+
{projects.map((project) => (
|
|
191
|
+
<li key={project.id}>
|
|
192
|
+
{project.name}
|
|
193
|
+
<IssueList issuesCollection={project.issues} />
|
|
194
|
+
</li>
|
|
195
|
+
))}
|
|
196
|
+
</ul>
|
|
197
|
+
)
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
// Child component subscribes to the child Collection
|
|
201
|
+
function IssueList({ issuesCollection }) {
|
|
202
|
+
const { data: issues } = useLiveQuery(issuesCollection)
|
|
203
|
+
return (
|
|
204
|
+
<ul>
|
|
205
|
+
{issues.map((issue) => (
|
|
206
|
+
<li key={issue.id}>{issue.title}</li>
|
|
207
|
+
))}
|
|
208
|
+
</ul>
|
|
209
|
+
)
|
|
210
|
+
}
|
|
211
|
+
```
|
|
212
|
+
|
|
213
|
+
Only the affected `IssueList` re-renders when an issue changes — the parent does not.
|
|
214
|
+
|
|
215
|
+
With `toArray()`, child results are plain arrays and the parent re-renders on child changes:
|
|
216
|
+
|
|
217
|
+
```tsx
|
|
218
|
+
import { toArray, eq } from '@tanstack/react-db'
|
|
219
|
+
|
|
220
|
+
const { data: projects } = useLiveQuery((q) =>
|
|
221
|
+
q.from({ p: projectsCollection }).select(({ p }) => ({
|
|
222
|
+
id: p.id,
|
|
223
|
+
name: p.name,
|
|
224
|
+
issues: toArray(
|
|
225
|
+
q
|
|
226
|
+
.from({ i: issuesCollection })
|
|
227
|
+
.where(({ i }) => eq(i.projectId, p.id))
|
|
228
|
+
.select(({ i }) => ({ id: i.id, title: i.title })),
|
|
229
|
+
),
|
|
230
|
+
})),
|
|
231
|
+
)
|
|
232
|
+
// project.issues is string[] — no subcomponent needed
|
|
233
|
+
```
|
|
234
|
+
|
|
235
|
+
See db-core/live-queries/SKILL.md for full includes rules (correlation conditions, nested includes, aggregates).
|
|
236
|
+
|
|
171
237
|
## Virtual Properties
|
|
172
238
|
|
|
173
239
|
Live query results include computed, read-only virtual properties on every row:
|