Skip to content

Commit 3008dbc

Browse files
authored
Allow using syncStream() instances with hooks (#729)
1 parent 76ea89c commit 3008dbc

File tree

3 files changed

+15
-1
lines changed

3 files changed

+15
-1
lines changed

.changeset/ninety-bears-own.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@powersync/react': patch
3+
---
4+
5+
Allow using `db.syncStream()` instances in `useQuery` hooks.

packages/react/src/hooks/streams.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ export interface UseSyncStreamOptions extends SyncStreamSubscribeOptions {
2424
* Parameters for the stream subscription. A single stream can have multiple subscriptions with different parameter
2525
* sets.
2626
*/
27-
parameters?: Record<string, any>;
27+
parameters?: Record<string, any> | null;
2828
}
2929

3030
/**

packages/react/tests/streams.test.tsx

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,15 @@ describe('stream hooks', () => {
5252
expect(currentStreams()).toStrictEqual([]);
5353
});
5454

55+
it('useQuery can take syncStream instance', async () => {
56+
const { result } = renderHook(() => useQuery('SELECT 1', [], { streams: [db.syncStream('a')] }), {
57+
wrapper: testWrapper
58+
});
59+
60+
// Not resolving the subscription.
61+
await waitFor(() => expect(result.current.data).toHaveLength(1), { timeout: 1000, interval: 100 });
62+
});
63+
5564
it('useQuery waiting on stream', async () => {
5665
const { result } = renderHook(
5766
() => useQuery('SELECT 1', [], { streams: [{ name: 'a', waitForStream: true }] }),

0 commit comments

Comments
 (0)