@durable-streams/state 0.2.4 → 0.2.5

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@durable-streams/state",
3
3
  "description": "State change event protocol for Durable Streams",
4
- "version": "0.2.4",
4
+ "version": "0.2.5",
5
5
  "author": "Durable Stream contributors",
6
6
  "license": "Apache-2.0",
7
7
  "repository": {
@@ -59,7 +59,7 @@
59
59
  "@tanstack/db": "latest",
60
60
  "@tanstack/intent": "latest",
61
61
  "tsdown": "^0.9.0",
62
- "@durable-streams/server": "0.3.0"
62
+ "@durable-streams/server": "0.3.1"
63
63
  },
64
64
  "engines": {
65
65
  "node": ">=18.0.0"
@@ -77,22 +77,34 @@ const messages = db.collections.messages
77
77
 
78
78
  ### Reactive queries with TanStack DB
79
79
 
80
- StreamDB collections are TanStack DB collections. Use framework adapters for reactive queries:
80
+ StreamDB collections are TanStack DB collections. Use framework adapters for reactive queries.
81
+
82
+ **IMPORTANT**: `useLiveQuery` returns `{ data }`, NOT the array directly. Always destructure with a default:
81
83
 
82
84
  ```typescript
83
85
  import { useLiveQuery } from "@tanstack/react-db"
84
86
  import { eq } from "@durable-streams/state"
85
87
 
88
+ // List query — destructure { data } with a default empty array
89
+ function UserList() {
90
+ const { data: users = [] } = useLiveQuery((q) =>
91
+ q.from({ users: db.collections.users })
92
+ )
93
+
94
+ return users.map(u => <div key={u.id}>{u.name}</div>)
95
+ }
96
+
97
+ // Single item query — use findOne(), data is T | undefined
86
98
  function UserProfile({ userId }: { userId: string }) {
87
- const userQuery = useLiveQuery((q) =>
99
+ const { data: user } = useLiveQuery((q) =>
88
100
  q
89
101
  .from({ users: db.collections.users })
90
102
  .where(({ users }) => eq(users.id, userId))
91
103
  .findOne()
92
104
  )
93
105
 
94
- if (!userQuery.data) return null
95
- return <div>{userQuery.data.name}</div>
106
+ if (!user) return null
107
+ return <div>{user.name}</div>
96
108
  }
97
109
  ```
98
110