Skip to content

Commit 36b5c06

Browse files
committed
style: Run prettier formatting
1 parent a67b7f7 commit 36b5c06

File tree

3 files changed

+29
-14
lines changed

3 files changed

+29
-14
lines changed

.changeset/suspense-query-hook.md

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ Add `useLiveSuspenseQuery` hook for React Suspense support
77
Introduces a new `useLiveSuspenseQuery` hook that provides declarative data loading with React Suspense, following TanStack Query's `useSuspenseQuery` pattern.
88

99
**Key features:**
10+
1011
- React 18+ compatible using the throw promise pattern
1112
- Type-safe API with guaranteed data (never undefined)
1213
- Automatic error handling via Error Boundaries
@@ -17,33 +18,37 @@ Introduces a new `useLiveSuspenseQuery` hook that provides declarative data load
1718
**Example usage:**
1819

1920
```tsx
20-
import { Suspense } from 'react';
21-
import { useLiveSuspenseQuery } from '@tanstack/react-db';
21+
import { Suspense } from "react"
22+
import { useLiveSuspenseQuery } from "@tanstack/react-db"
2223

2324
function TodoList() {
2425
// Data is guaranteed to be defined - no isLoading needed
2526
const { data } = useLiveSuspenseQuery((q) =>
26-
q.from({ todos: todosCollection })
27+
q
28+
.from({ todos: todosCollection })
2729
.where(({ todos }) => eq(todos.completed, false))
28-
);
30+
)
2931

3032
return (
3133
<ul>
32-
{data.map(todo => <li key={todo.id}>{todo.text}</li>)}
34+
{data.map((todo) => (
35+
<li key={todo.id}>{todo.text}</li>
36+
))}
3337
</ul>
34-
);
38+
)
3539
}
3640

3741
function App() {
3842
return (
3943
<Suspense fallback={<div>Loading...</div>}>
4044
<TodoList />
4145
</Suspense>
42-
);
46+
)
4347
}
4448
```
4549

4650
**Implementation details:**
51+
4752
- Throws promises when collection is loading (caught by Suspense)
4853
- Throws errors when collection fails (caught by Error Boundary)
4954
- Reuses promise across re-renders to prevent infinite loops

packages/react-db/src/useLiveSuspenseQuery.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -250,9 +250,9 @@ export function useLiveSuspenseQuery(
250250
}
251251

252252
// Create stable subscribe function using ref
253-
const subscribeRef = useRef<((onStoreChange: () => void) => () => void) | null>(
254-
null
255-
)
253+
const subscribeRef = useRef<
254+
((onStoreChange: () => void) => () => void) | null
255+
>(null)
256256
if (!subscribeRef.current || needsNewCollection) {
257257
subscribeRef.current = (onStoreChange: () => void) => {
258258
const subscription = collection.subscribeChanges(() => {

packages/react-db/tests/useLiveSuspenseQuery.test.tsx

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,9 @@ describe(`useLiveSuspenseQuery`, () => {
164164
)
165165

166166
const liveQuery = createLiveQueryCollection((q) =>
167-
q.from({ persons: collection }).where(({ persons }) => gt(persons.age, 30))
167+
q
168+
.from({ persons: collection })
169+
.where(({ persons }) => gt(persons.age, 30))
168170
)
169171

170172
const { result } = renderHook(() => useLiveSuspenseQuery(liveQuery), {
@@ -194,7 +196,10 @@ describe(`useLiveSuspenseQuery`, () => {
194196
const { result, rerender } = renderHook(
195197
({ minAge }) => {
196198
return useLiveSuspenseQuery(
197-
(q) => q.from({ persons: collection }).where(({ persons }) => gt(persons.age, minAge)),
199+
(q) =>
200+
q
201+
.from({ persons: collection })
202+
.where(({ persons }) => gt(persons.age, minAge)),
198203
[minAge]
199204
)
200205
},
@@ -337,9 +342,14 @@ describe(`useLiveSuspenseQuery`, () => {
337342

338343
const { result } = renderHook(
339344
() => {
340-
const persons = useLiveSuspenseQuery((q) => q.from({ persons: personsCollection }))
345+
const persons = useLiveSuspenseQuery((q) =>
346+
q.from({ persons: personsCollection })
347+
)
341348
const johnDoe = useLiveSuspenseQuery((q) =>
342-
q.from({ persons: personsCollection }).where(({ persons }) => eq(persons.id, `1`)).findOne()
349+
q
350+
.from({ persons: personsCollection })
351+
.where(({ persons }) => eq(persons.id, `1`))
352+
.findOne()
343353
)
344354
return { persons, johnDoe }
345355
},

0 commit comments

Comments
 (0)