Skip to content

Commit 341ab00

Browse files
committed
Added a jsdoc example snippet.
1 parent c1f96ac commit 341ab00

File tree

1 file changed

+22
-1
lines changed

1 file changed

+22
-1
lines changed

packages/react/src/hooks/useSuspenseQuery.ts

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,33 @@
11
import React from 'react';
22
import { generateQueryKey, getQueryStore } from '../QueryStore';
33
import { usePowerSync } from './PowerSyncContext';
4-
import { CompilableQuery, ParsedQuery, parseQuery, SQLWatchOptions } from '@powersync/common';
4+
import { CompilableQuery, ParsedQuery, parseQuery } from '@powersync/common';
55
import { WatchedQuery } from '../WatchedQuery';
66
import { AdditionalOptions, QueryResult } from './useQuery';
77

88
export type SuspenseQueryResult<T> = Pick<QueryResult<T>, 'data' | 'refresh'>;
99

10+
/**
11+
* A hook to access the results of a watched query that suspends until the initial result has loaded.
12+
* @example
13+
* export const ContentComponent = () => {
14+
* const { data: lists } = useSuspenseQuery('SELECT * from lists');
15+
*
16+
* return <View>
17+
* {lists.map((l) => (
18+
* <Text key={l.id}>{JSON.stringify(l)}</Text>
19+
* ))}
20+
* </View>;
21+
* }
22+
*
23+
* export const DisplayComponent = () => {
24+
* return (
25+
* <Suspense fallback={<div>Loading content...</div>}>
26+
* <ContentComponent />
27+
* </Suspense>
28+
* );
29+
* }
30+
*/
1031
export const useSuspenseQuery = <T = any>(
1132
query: string | CompilableQuery<T>,
1233
parameters: any[] = [],

0 commit comments

Comments
 (0)