@@ -11,7 +11,7 @@ title: useLiveQuery
1111function useLiveQuery<TContext >(queryFn ): object ;
1212```
1313
14- Defined in: [ useLiveQuery.ts:80 ] ( https://github.com/TanStack/db/blob/main/packages/solid-db/src/useLiveQuery.ts#L80 )
14+ Defined in: [ useLiveQuery.ts:84 ] ( https://github.com/TanStack/db/blob/main/packages/solid-db/src/useLiveQuery.ts#L84 )
1515
1616Create a live query using a query function
1717
@@ -149,11 +149,155 @@ return (
149149
150150## Call Signature
151151
152+ ``` ts
153+ function useLiveQuery<TContext >(queryFn ): object ;
154+ ```
155+
156+ Defined in: [ useLiveQuery.ts:99] ( https://github.com/TanStack/db/blob/main/packages/solid-db/src/useLiveQuery.ts#L99 )
157+
158+ Create a live query using a query function
159+
160+ ### Type Parameters
161+
162+ #### TContext
163+
164+ ` TContext ` * extends* ` Context `
165+
166+ ### Parameters
167+
168+ #### queryFn
169+
170+ (` q ` ) => ` QueryBuilder ` \< ` TContext ` \> \| ` null ` \| ` undefined `
171+
172+ Query function that defines what data to fetch
173+
174+ ### Returns
175+
176+ ` object `
177+
178+ Object with reactive data, state, and status information
179+
180+ #### collection
181+
182+ ``` ts
183+ collection : Accessor <
184+ | Collection < { [K in string | number | symbol ]: (TContext [" result" ] extends object ? any [any ] : TContext [" hasJoins" ] extends true ? TContext [" schema" ] : TContext [" schema" ][TContext [" fromSourceName" ]])[K ] }, string | number , {
185+ }, StandardSchemaV1 < unknown , unknown > , { [K in string | number | symbol ]: (TContext [" result" ] extends object ? any [any ] : TContext [" hasJoins" ] extends true ? TContext [" schema" ] : TContext [" schema" ][TContext [" fromSourceName" ]])[K ] }>
186+ | null > ;
187+ ```
188+
189+ #### data
190+
191+ ``` ts
192+ data : { [K in string | number | symbol ]: (TContext [" result" ] extends object ? any [any ] : TContext [" hasJoins" ] extends true ? TContext [" schema" ] : TContext [" schema" ][TContext [" fromSourceName" ]])[K ] }[];
193+ ```
194+
195+ #### isCleanedUp
196+
197+ ``` ts
198+ isCleanedUp : Accessor < boolean > ;
199+ ```
200+
201+ #### isError
202+
203+ ``` ts
204+ isError : Accessor < boolean > ;
205+ ```
206+
207+ #### isIdle
208+
209+ ``` ts
210+ isIdle : Accessor < boolean > ;
211+ ```
212+
213+ #### isLoading
214+
215+ ``` ts
216+ isLoading : Accessor < boolean > ;
217+ ```
218+
219+ #### isReady
220+
221+ ``` ts
222+ isReady : Accessor < boolean > ;
223+ ```
224+
225+ #### state
226+
227+ ``` ts
228+ state : ReactiveMap < string | number , { [K in string | number | symbol ]: (TContext [" result" ] extends object ? any [any ] : TContext [" hasJoins" ] extends true ? TContext [" schema" ] : TContext [" schema" ][TContext [" fromSourceName" ]])[K ] }> ;
229+ ```
230+
231+ #### status
232+
233+ ``` ts
234+ status : Accessor < CollectionStatus | " disabled" > ;
235+ ```
236+
237+ ### Examples
238+
239+ ``` ts
240+ // Basic query with object syntax
241+ const todosQuery = useLiveQuery ((q ) =>
242+ q .from ({ todos: todosCollection })
243+ .where (({ todos }) => eq (todos .completed , false ))
244+ .select (({ todos }) => ({ id: todos .id , text: todos .text }))
245+ )
246+ ```
247+
248+ ``` ts
249+ // With dependencies that trigger re-execution
250+ const todosQuery = useLiveQuery (
251+ (q ) => q .from ({ todos: todosCollection })
252+ .where (({ todos }) => gt (todos .priority , minPriority ())),
253+ )
254+ ```
255+
256+ ``` ts
257+ // Join pattern
258+ const personIssues = useLiveQuery ((q ) =>
259+ q .from ({ issues: issueCollection })
260+ .join ({ persons: personCollection }, ({ issues , persons }) =>
261+ eq (issues .userId , persons .id )
262+ )
263+ .select (({ issues , persons }) => ({
264+ id: issues .id ,
265+ title: issues .title ,
266+ userName: persons .name
267+ }))
268+ )
269+ ```
270+
271+ ``` ts
272+ // Handle loading and error states
273+ const todosQuery = useLiveQuery ((q ) =>
274+ q .from ({ todos: todoCollection })
275+ )
276+
277+ return (
278+ <Switch >
279+ < Match when = {todosQuery.isLoading()}>
280+ <div >Loading ... < / div >
281+ < / Match >
282+ < Match when = {todosQuery.isError()}>
283+ <div >Error : {todosQuery .status ()}</div >
284+ < / Match >
285+ < Match when = {todosQuery.isReady()}>
286+ < For each = {todosQuery.data()}>
287+ {(todo ) = > <li key ={todo .id}>{todo.text }< / li > }
288+ < / For >
289+ < / Match >
290+ < / Switch >
291+ )
292+ ```
293+
294+ ## Call Signature
295+
152296``` ts
153297function useLiveQuery<TContext >(config ): object ;
154298```
155299
156- Defined in: [ useLiveQuery.ts:135 ] ( https://github.com/TanStack/db/blob/main/packages/solid-db/src/useLiveQuery.ts#L135 )
300+ Defined in: [ useLiveQuery.ts:158 ] ( https://github.com/TanStack/db/blob/main/packages/solid-db/src/useLiveQuery.ts#L158 )
157301
158302Create a live query using configuration object
159303
@@ -279,7 +423,7 @@ return (
279423function useLiveQuery<TResult , TKey , TUtils >(liveQueryCollection ): object ;
280424```
281425
282- Defined in: [ useLiveQuery.ts:185 ] ( https://github.com/TanStack/db/blob/main/packages/solid-db/src/useLiveQuery.ts#L185 )
426+ Defined in: [ useLiveQuery.ts:208 ] ( https://github.com/TanStack/db/blob/main/packages/solid-db/src/useLiveQuery.ts#L208 )
283427
284428Subscribe to an existing live query collection
285429
0 commit comments