Open History to see the last commit
1---
2id: useLiveQuery
3title: useLiveQuery
4---
5
6# Function: useLiveQuery()
7
8## Call Signature
9
10```ts
11function useLiveQuery<TContext>(queryFn, deps?): object;
12```
13
14Defined in: [useLiveQuery.ts:84](https://github.com/TanStack/db/blob/main/packages/react-db/src/useLiveQuery.ts#L84)
15
16Create a live query using a query function
17
18### Type Parameters
19
20#### TContext
21
22`TContext` *extends* `Context`
23
24### Parameters
25
26#### queryFn
27
28(`q`) => `QueryBuilder`\<`TContext`\>
29
30Query function that defines what data to fetch
31
32#### deps?
33
34`unknown`[]
35
36Array of dependencies that trigger query re-execution when changed
37
38### Returns
39
40`object`
41
42Object with reactive data, state, and status information
43
44#### collection
45
46```ts
47collection: Collection<{ [K in string | number | symbol]: ResultValue<TContext>[K] }, string | number, {
48}>;
49```
50
51#### data
52
53```ts
54data: InferResultType<TContext>;
55```
56
57#### isCleanedUp
58
59```ts
60isCleanedUp: boolean;
61```
62
63#### isEnabled
64
65```ts
66isEnabled: true;
67```
68
69#### isError
70
71```ts
72isError: boolean;
73```
74
75#### isIdle
76
77```ts
78isIdle: boolean;
79```
80
81#### isLoading
82
83```ts
84isLoading: boolean;
85```
86
87#### isReady
88
89```ts
90isReady: boolean;
91```
92
93#### state
94
95```ts
96state: Map<string | number, { [K in string | number | symbol]: ResultValue<TContext>[K] }>;
97```
98
99#### status
100
101```ts
102status: CollectionStatus;
103```
104
105### Examples
106
107```ts
108// Basic query with object syntax
109const { data, isLoading } = useLiveQuery((q) =>
110 q.from({ todos: todosCollection })
111 .where(({ todos }) => eq(todos.completed, false))
112 .select(({ todos }) => ({ id: todos.id, text: todos.text }))
113)
114```
115
116```ts
117// Single result query
118const { data } = useLiveQuery(
119 (q) => q.from({ todos: todosCollection })
120 .where(({ todos }) => eq(todos.id, 1))
121 .findOne()
122)
123```
124
125```ts
126// With dependencies that trigger re-execution
127const { data, state } = useLiveQuery(
128 (q) => q.from({ todos: todosCollection })
129 .where(({ todos }) => gt(todos.priority, minPriority)),
130 [minPriority] // Re-run when minPriority changes
131)
132```
133
134```ts
135// Join pattern
136const { data } = useLiveQuery((q) =>
137 q.from({ issues: issueCollection })
138 .join({ persons: personCollection }, ({ issues, persons }) =>
139 eq(issues.userId, persons.id)
140 )
141 .select(({ issues, persons }) => ({
142 id: issues.id,
143 title: issues.title,
144 userName: persons.name
145 }))
146)
147```
148
149```ts
150// Handle loading and error states
151const { data, isLoading, isError, status } = useLiveQuery((q) =>
152 q.from({ todos: todoCollection })
153)
154
155if (isLoading) return <div>Loading...</div>
156if (isError) return <div>Error: {status}</div>
157
158return (
159 <ul>
160 {data.map(todo => <li key={todo.id}>{todo.text}</li>)}
161 </ul>
162)
163```
164
165## Call Signature
166
167```ts
168function useLiveQuery<TContext>(queryFn, deps?): object;
169```
170
171Defined in: [useLiveQuery.ts:101](https://github.com/TanStack/db/blob/main/packages/react-db/src/useLiveQuery.ts#L101)
172
173Create a live query using a query function
174
175### Type Parameters
176
177#### TContext
178
179`TContext` *extends* `Context`
180
181### Parameters
182
183#### queryFn
184
185(`q`) => `QueryBuilder`\<`TContext`\> \| `null` \| `undefined`
186
187Query function that defines what data to fetch
188
189#### deps?
190
191`unknown`[]
192
193Array of dependencies that trigger query re-execution when changed
194
195### Returns
196
197`object`
198
199Object with reactive data, state, and status information
200
201#### collection
202
203```ts
204collection:
205 | Collection<{ [K in string | number | symbol]: ResultValue<TContext>[K] }, string | number, {
206}, StandardSchemaV1<unknown, unknown>, { [K in string | number | symbol]: ResultValue<TContext>[K] }>
207 | undefined;
208```
209
210#### data
211
212```ts
213data: InferResultType<TContext> | undefined;
214```
215
216#### isCleanedUp
217
218```ts
219isCleanedUp: boolean;
220```
221
222#### isEnabled
223
224```ts
225isEnabled: boolean;
226```
227
228#### isError
229
230```ts
231isError: boolean;
232```
233
234#### isIdle
235
236```ts
237isIdle: boolean;
238```
239
240#### isLoading
241
242```ts
243isLoading: boolean;
244```
245
246#### isReady
247
248```ts
249isReady: boolean;
250```
251
252#### state
253
254```ts
255state:
256 | Map<string | number, { [K in string | number | symbol]: ResultValue<TContext>[K] }>
257 | undefined;
258```
259
260#### status
261
262```ts
263status: UseLiveQueryStatus;
264```
265
266### Examples
267
268```ts
269// Basic query with object syntax
270const { data, isLoading } = useLiveQuery((q) =>
271 q.from({ todos: todosCollection })
272 .where(({ todos }) => eq(todos.completed, false))
273 .select(({ todos }) => ({ id: todos.id, text: todos.text }))
274)
275```
276
277```ts
278// Single result query
279const { data } = useLiveQuery(
280 (q) => q.from({ todos: todosCollection })
281 .where(({ todos }) => eq(todos.id, 1))
282 .findOne()
283)
284```
285
286```ts
287// With dependencies that trigger re-execution
288const { data, state } = useLiveQuery(
289 (q) => q.from({ todos: todosCollection })
290 .where(({ todos }) => gt(todos.priority, minPriority)),
291 [minPriority] // Re-run when minPriority changes
292)
293```
294
295```ts
296// Join pattern
297const { data } = useLiveQuery((q) =>
298 q.from({ issues: issueCollection })
299 .join({ persons: personCollection }, ({ issues, persons }) =>
300 eq(issues.userId, persons.id)
301 )
302 .select(({ issues, persons }) => ({
303 id: issues.id,
304 title: issues.title,
305 userName: persons.name
306 }))
307)
308```
309
310```ts
311// Handle loading and error states
312const { data, isLoading, isError, status } = useLiveQuery((q) =>
313 q.from({ todos: todoCollection })
314)
315
316if (isLoading) return <div>Loading...</div>
317if (isError) return <div>Error: {status}</div>
318
319return (
320 <ul>
321 {data.map(todo => <li key={todo.id}>{todo.text}</li>)}
322 </ul>
323)
324```
325
326## Call Signature
327
328```ts
329function useLiveQuery<TContext>(queryFn, deps?): object;
330```
331
332Defined in: [useLiveQuery.ts:120](https://github.com/TanStack/db/blob/main/packages/react-db/src/useLiveQuery.ts#L120)
333
334Create a live query using a query function
335
336### Type Parameters
337
338#### TContext
339
340`TContext` *extends* `Context`
341
342### Parameters
343
344#### queryFn
345
346(`q`) =>
347 \| `LiveQueryCollectionConfig`\<`TContext`, `RootQueryResult`\<`TContext`\>\>
348 \| `null`
349 \| `undefined`
350
351Query function that defines what data to fetch
352
353#### deps?
354
355`unknown`[]
356
357Array of dependencies that trigger query re-execution when changed
358
359### Returns
360
361`object`
362
363Object with reactive data, state, and status information
364
365#### collection
366
367```ts
368collection:
369 | Collection<{ [K in string | number | symbol]: ResultValue<TContext>[K] }, string | number, {
370}, StandardSchemaV1<unknown, unknown>, { [K in string | number | symbol]: ResultValue<TContext>[K] }>
371 | undefined;
372```
373
374#### data
375
376```ts
377data: InferResultType<TContext> | undefined;
378```
379
380#### isCleanedUp
381
382```ts
383isCleanedUp: boolean;
384```
385
386#### isEnabled
387
388```ts
389isEnabled: boolean;
390```
391
392#### isError
393
394```ts
395isError: boolean;
396```
397
398#### isIdle
399
400```ts
401isIdle: boolean;
402```
403
404#### isLoading
405
406```ts
407isLoading: boolean;
408```
409
410#### isReady
411
412```ts
413isReady: boolean;
414```
415
416#### state
417
418```ts
419state:
420 | Map<string | number, { [K in string | number | symbol]: ResultValue<TContext>[K] }>
421 | undefined;
422```
423
424#### status
425
426```ts
427status: UseLiveQueryStatus;
428```
429
430### Examples
431
432```ts
433// Basic query with object syntax
434const { data, isLoading } = useLiveQuery((q) =>
435 q.from({ todos: todosCollection })
436 .where(({ todos }) => eq(todos.completed, false))
437 .select(({ todos }) => ({ id: todos.id, text: todos.text }))
438)
439```
440
441```ts
442// Single result query
443const { data } = useLiveQuery(
444 (q) => q.from({ todos: todosCollection })
445 .where(({ todos }) => eq(todos.id, 1))
446 .findOne()
447)
448```
449
450```ts
451// With dependencies that trigger re-execution
452const { data, state } = useLiveQuery(
453 (q) => q.from({ todos: todosCollection })
454 .where(({ todos }) => gt(todos.priority, minPriority)),
455 [minPriority] // Re-run when minPriority changes
456)
457```
458
459```ts
460// Join pattern
461const { data } = useLiveQuery((q) =>
462 q.from({ issues: issueCollection })
463 .join({ persons: personCollection }, ({ issues, persons }) =>
464 eq(issues.userId, persons.id)
465 )
466 .select(({ issues, persons }) => ({
467 id: issues.id,
468 title: issues.title,
469 userName: persons.name
470 }))
471)
472```
473
474```ts
475// Handle loading and error states
476const { data, isLoading, isError, status } = useLiveQuery((q) =>
477 q.from({ todos: todoCollection })
478)
479
480if (isLoading) return <div>Loading...</div>
481if (isError) return <div>Error: {status}</div>
482
483return (
484 <ul>
485 {data.map(todo => <li key={todo.id}>{todo.text}</li>)}
486 </ul>
487)
488```
489
490## Call Signature
491
492```ts
493function useLiveQuery<TResult, TKey, TUtils>(queryFn, deps?): object;
494```
495
496Defined in: [useLiveQuery.ts:139](https://github.com/TanStack/db/blob/main/packages/react-db/src/useLiveQuery.ts#L139)
497
498Create a live query using a query function
499
500### Type Parameters
501
502#### TResult
503
504`TResult` *extends* `object`
505
506#### TKey
507
508`TKey` *extends* `string` \| `number`
509
510#### TUtils
511
512`TUtils` *extends* `Record`\<`string`, `any`\>
513
514### Parameters
515
516#### queryFn
517
518(`q`) =>
519 \| `Collection`\<`TResult`, `TKey`, `TUtils`, `StandardSchemaV1`\<`unknown`, `unknown`\>, `TResult`\>
520 \| `null`
521 \| `undefined`
522
523Query function that defines what data to fetch
524
525#### deps?
526
527`unknown`[]
528
529Array of dependencies that trigger query re-execution when changed
530
531### Returns
532
533`object`
534
535Object with reactive data, state, and status information
536
537#### collection
538
539```ts
540collection:
541 | Collection<TResult, TKey, TUtils, StandardSchemaV1<unknown, unknown>, TResult>
542 | undefined;
543```
544
545#### data
546
547```ts
548data: TResult[] | undefined;
549```
550
551#### isCleanedUp
552
553```ts
554isCleanedUp: boolean;
555```
556
557#### isEnabled
558
559```ts
560isEnabled: boolean;
561```
562
563#### isError
564
565```ts
566isError: boolean;
567```
568
569#### isIdle
570
571```ts
572isIdle: boolean;
573```
574
575#### isLoading
576
577```ts
578isLoading: boolean;
579```
580
581#### isReady
582
583```ts
584isReady: boolean;
585```
586
587#### state
588
589```ts
590state: Map<TKey, TResult> | undefined;
591```
592
593#### status
594
595```ts
596status: UseLiveQueryStatus;
597```
598
599### Examples
600
601```ts
602// Basic query with object syntax
603const { data, isLoading } = useLiveQuery((q) =>
604 q.from({ todos: todosCollection })
605 .where(({ todos }) => eq(todos.completed, false))
606 .select(({ todos }) => ({ id: todos.id, text: todos.text }))
607)
608```
609
610```ts
611// Single result query
612const { data } = useLiveQuery(
613 (q) => q.from({ todos: todosCollection })
614 .where(({ todos }) => eq(todos.id, 1))
615 .findOne()
616)
617```
618
619```ts
620// With dependencies that trigger re-execution
621const { data, state } = useLiveQuery(
622 (q) => q.from({ todos: todosCollection })
623 .where(({ todos }) => gt(todos.priority, minPriority)),
624 [minPriority] // Re-run when minPriority changes
625)
626```
627
628```ts
629// Join pattern
630const { data } = useLiveQuery((q) =>
631 q.from({ issues: issueCollection })
632 .join({ persons: personCollection }, ({ issues, persons }) =>
633 eq(issues.userId, persons.id)
634 )
635 .select(({ issues, persons }) => ({
636 id: issues.id,
637 title: issues.title,
638 userName: persons.name
639 }))
640)
641```
642
643```ts
644// Handle loading and error states
645const { data, isLoading, isError, status } = useLiveQuery((q) =>
646 q.from({ todos: todoCollection })
647)
648
649if (isLoading) return <div>Loading...</div>
650if (isError) return <div>Error: {status}</div>
651
652return (
653 <ul>
654 {data.map(todo => <li key={todo.id}>{todo.text}</li>)}
655 </ul>
656)
657```
658
659## Call Signature
660
661```ts
662function useLiveQuery<TContext, TResult, TKey, TUtils>(queryFn, deps?): object;
663```
664
665Defined in: [useLiveQuery.ts:162](https://github.com/TanStack/db/blob/main/packages/react-db/src/useLiveQuery.ts#L162)
666
667Create a live query using a query function
668
669### Type Parameters
670
671#### TContext
672
673`TContext` *extends* `Context`
674
675#### TResult
676
677`TResult` *extends* `object`
678
679#### TKey
680
681`TKey` *extends* `string` \| `number`
682
683#### TUtils
684
685`TUtils` *extends* `Record`\<`string`, `any`\>
686
687### Parameters
688
689#### queryFn
690
691(`q`) =>
692 \| `QueryBuilder`\<`TContext`\>
693 \| `LiveQueryCollectionConfig`\<`TContext`, `RootQueryResult`\<`TContext`\>\>
694 \| `Collection`\<`TResult`, `TKey`, `TUtils`, `StandardSchemaV1`\<`unknown`, `unknown`\>, `TResult`\>
695 \| `null`
696 \| `undefined`
697
698Query function that defines what data to fetch
699
700#### deps?
701
702`unknown`[]
703
704Array of dependencies that trigger query re-execution when changed
705
706### Returns
707
708`object`
709
710Object with reactive data, state, and status information
711
712#### collection
713
714```ts
715collection:
716 | Collection<TResult, TKey, TUtils, StandardSchemaV1<unknown, unknown>, TResult>
717 | Collection<{ [K in string | number | symbol]: ResultValue<TContext>[K] }, string | number, {
718}, StandardSchemaV1<unknown, unknown>, { [K in string | number | symbol]: ResultValue<TContext>[K] }>
719 | undefined;
720```
721
722#### data
723
724```ts
725data: InferResultType<TContext> | TResult[] | undefined;
726```
727
728#### isCleanedUp
729
730```ts
731isCleanedUp: boolean;
732```
733
734#### isEnabled
735
736```ts
737isEnabled: boolean;
738```
739
740#### isError
741
742```ts
743isError: boolean;
744```
745
746#### isIdle
747
748```ts
749isIdle: boolean;
750```
751
752#### isLoading
753
754```ts
755isLoading: boolean;
756```
757
758#### isReady
759
760```ts
761isReady: boolean;
762```
763
764#### state
765
766```ts
767state:
768 | Map<string | number, { [K in string | number | symbol]: ResultValue<TContext>[K] }>
769 | Map<TKey, TResult>
770 | undefined;
771```
772
773#### status
774
775```ts
776status: UseLiveQueryStatus;
777```
778
779### Examples
780
781```ts
782// Basic query with object syntax
783const { data, isLoading } = useLiveQuery((q) =>
784 q.from({ todos: todosCollection })
785 .where(({ todos }) => eq(todos.completed, false))
786 .select(({ todos }) => ({ id: todos.id, text: todos.text }))
787)
788```
789
790```ts
791// Single result query
792const { data } = useLiveQuery(
793 (q) => q.from({ todos: todosCollection })
794 .where(({ todos }) => eq(todos.id, 1))
795 .findOne()
796)
797```
798
799```ts
800// With dependencies that trigger re-execution
801const { data, state } = useLiveQuery(
802 (q) => q.from({ todos: todosCollection })
803 .where(({ todos }) => gt(todos.priority, minPriority)),
804 [minPriority] // Re-run when minPriority changes
805)
806```
807
808```ts
809// Join pattern
810const { data } = useLiveQuery((q) =>
811 q.from({ issues: issueCollection })
812 .join({ persons: personCollection }, ({ issues, persons }) =>
813 eq(issues.userId, persons.id)
814 )
815 .select(({ issues, persons }) => ({
816 id: issues.id,
817 title: issues.title,
818 userName: persons.name
819 }))
820)
821```
822
823```ts
824// Handle loading and error states
825const { data, isLoading, isError, status } = useLiveQuery((q) =>
826 q.from({ todos: todoCollection })
827)
828
829if (isLoading) return <div>Loading...</div>
830if (isError) return <div>Error: {status}</div>
831
832return (
833 <ul>
834 {data.map(todo => <li key={todo.id}>{todo.text}</li>)}
835 </ul>
836)
837```
838
839## Call Signature
840
841```ts
842function useLiveQuery<TContext>(config, deps?): object;
843```
844
845Defined in: [useLiveQuery.ts:230](https://github.com/TanStack/db/blob/main/packages/react-db/src/useLiveQuery.ts#L230)
846
847Create a live query using configuration object
848
849### Type Parameters
850
851#### TContext
852
853`TContext` *extends* `Context`
854
855### Parameters
856
857#### config
858
859`LiveQueryCollectionConfig`\<`TContext`\>
860
861Configuration object with query and options
862
863#### deps?
864
865`unknown`[]
866
867Array of dependencies that trigger query re-execution when changed
868
869### Returns
870
871`object`
872
873Object with reactive data, state, and status information
874
875#### collection
876
877```ts
878collection: Collection<{ [K in string | number | symbol]: ResultValue<TContext>[K] }, string | number, {
879}>;
880```
881
882#### data
883
884```ts
885data: InferResultType<TContext>;
886```
887
888#### isCleanedUp
889
890```ts
891isCleanedUp: boolean;
892```
893
894#### isEnabled
895
896```ts
897isEnabled: true;
898```
899
900#### isError
901
902```ts
903isError: boolean;
904```
905
906#### isIdle
907
908```ts
909isIdle: boolean;
910```
911
912#### isLoading
913
914```ts
915isLoading: boolean;
916```
917
918#### isReady
919
920```ts
921isReady: boolean;
922```
923
924#### state
925
926```ts
927state: Map<string | number, { [K in string | number | symbol]: ResultValue<TContext>[K] }>;
928```
929
930#### status
931
932```ts
933status: CollectionStatus;
934```
935
936### Examples
937
938```ts
939// Basic config object usage
940const { data, status } = useLiveQuery({
941 query: (q) => q.from({ todos: todosCollection }),
942 gcTime: 60000
943})
944```
945
946```ts
947// With query builder and options
948const queryBuilder = new Query()
949 .from({ persons: collection })
950 .where(({ persons }) => gt(persons.age, 30))
951 .select(({ persons }) => ({ id: persons.id, name: persons.name }))
952
953const { data, isReady } = useLiveQuery({ query: queryBuilder })
954```
955
956```ts
957// Handle all states uniformly
958const { data, isLoading, isReady, isError } = useLiveQuery({
959 query: (q) => q.from({ items: itemCollection })
960})
961
962if (isLoading) return <div>Loading...</div>
963if (isError) return <div>Something went wrong</div>
964if (!isReady) return <div>Preparing...</div>
965
966return <div>{data.length} items loaded</div>
967```
968
969## Call Signature
970
971```ts
972function useLiveQuery<TResult, TKey, TUtils>(liveQueryCollection): object;
973```
974
975Defined in: [useLiveQuery.ts:276](https://github.com/TanStack/db/blob/main/packages/react-db/src/useLiveQuery.ts#L276)
976
977Subscribe to an existing live query collection
978
979### Type Parameters
980
981#### TResult
982
983`TResult` *extends* `object`
984
985#### TKey
986
987`TKey` *extends* `string` \| `number`
988
989#### TUtils
990
991`TUtils` *extends* `Record`\<`string`, `any`\>
992
993### Parameters
994
995#### liveQueryCollection
996
997`Collection`\<`TResult`, `TKey`, `TUtils`, `StandardSchemaV1`\<`unknown`, `unknown`\>, `TResult`\> & `NonSingleResult`
998
999Pre-created live query collection to subscribe to
1000
1001### Returns
1002
1003`object`
1004
1005Object with reactive data, state, and status information
1006
1007#### collection
1008
1009```ts
1010collection: Collection<TResult, TKey, TUtils>;
1011```
1012
1013#### data
1014
1015```ts
1016data: TResult[];
1017```
1018
1019#### isCleanedUp
1020
1021```ts
1022isCleanedUp: boolean;
1023```
1024
1025#### isEnabled
1026
1027```ts
1028isEnabled: true;
1029```
1030
1031#### isError
1032
1033```ts
1034isError: boolean;
1035```
1036
1037#### isIdle
1038
1039```ts
1040isIdle: boolean;
1041```
1042
1043#### isLoading
1044
1045```ts
1046isLoading: boolean;
1047```
1048
1049#### isReady
1050
1051```ts
1052isReady: boolean;
1053```
1054
1055#### state
1056
1057```ts
1058state: Map<TKey, TResult>;
1059```
1060
1061#### status
1062
1063```ts
1064status: CollectionStatus;
1065```
1066
1067### Examples
1068
1069```ts
1070// Using pre-created live query collection
1071const myLiveQuery = createLiveQueryCollection((q) =>
1072 q.from({ todos: todosCollection }).where(({ todos }) => eq(todos.active, true))
1073)
1074const { data, collection } = useLiveQuery(myLiveQuery)
1075```
1076
1077```ts
1078// Access collection methods directly
1079const { data, collection, isReady } = useLiveQuery(existingCollection)
1080
1081// Use collection for mutations
1082const handleToggle = (id) => {
1083 collection.update(id, draft => { draft.completed = !draft.completed })
1084}
1085```
1086
1087```ts
1088// Handle states consistently
1089const { data, isLoading, isError } = useLiveQuery(sharedCollection)
1090
1091if (isLoading) return <div>Loading...</div>
1092if (isError) return <div>Error loading data</div>
1093
1094return <div>{data.map(item => <Item key={item.id} {...item} />)}</div>
1095```
1096
1097## Call Signature
1098
1099```ts
1100function useLiveQuery<TResult, TKey, TUtils>(liveQueryCollection): object;
1101```
1102
1103Defined in: [useLiveQuery.ts:296](https://github.com/TanStack/db/blob/main/packages/react-db/src/useLiveQuery.ts#L296)
1104
1105Create a live query using a query function
1106
1107### Type Parameters
1108
1109#### TResult
1110
1111`TResult` *extends* `object`
1112
1113#### TKey
1114
1115`TKey` *extends* `string` \| `number`
1116
1117#### TUtils
1118
1119`TUtils` *extends* `Record`\<`string`, `any`\>
1120
1121### Parameters
1122
1123#### liveQueryCollection
1124
1125`Collection`\<`TResult`, `TKey`, `TUtils`, `StandardSchemaV1`\<`unknown`, `unknown`\>, `TResult`\> & `SingleResult`
1126
1127### Returns
1128
1129`object`
1130
1131Object with reactive data, state, and status information
1132
1133#### collection
1134
1135```ts
1136collection: Collection<TResult, TKey, TUtils, StandardSchemaV1<unknown, unknown>, TResult> & SingleResult;
1137```
1138
1139#### data
1140
1141```ts
1142data: TResult | undefined;
1143```
1144
1145#### isCleanedUp
1146
1147```ts
1148isCleanedUp: boolean;
1149```
1150
1151#### isEnabled
1152
1153```ts
1154isEnabled: true;
1155```
1156
1157#### isError
1158
1159```ts
1160isError: boolean;
1161```
1162
1163#### isIdle
1164
1165```ts
1166isIdle: boolean;
1167```
1168
1169#### isLoading
1170
1171```ts
1172isLoading: boolean;
1173```
1174
1175#### isReady
1176
1177```ts
1178isReady: boolean;
1179```
1180
1181#### state
1182
1183```ts
1184state: Map<TKey, TResult>;
1185```
1186
1187#### status
1188
1189```ts
1190status: CollectionStatus;
1191```
1192
1193### Examples
1194
1195```ts
1196// Basic query with object syntax
1197const { data, isLoading } = useLiveQuery((q) =>
1198 q.from({ todos: todosCollection })
1199 .where(({ todos }) => eq(todos.completed, false))
1200 .select(({ todos }) => ({ id: todos.id, text: todos.text }))
1201)
1202```
1203
1204```ts
1205// Single result query
1206const { data } = useLiveQuery(
1207 (q) => q.from({ todos: todosCollection })
1208 .where(({ todos }) => eq(todos.id, 1))
1209 .findOne()
1210)
1211```
1212
1213```ts
1214// With dependencies that trigger re-execution
1215const { data, state } = useLiveQuery(
1216 (q) => q.from({ todos: todosCollection })
1217 .where(({ todos }) => gt(todos.priority, minPriority)),
1218 [minPriority] // Re-run when minPriority changes
1219)
1220```
1221
1222```ts
1223// Join pattern
1224const { data } = useLiveQuery((q) =>
1225 q.from({ issues: issueCollection })
1226 .join({ persons: personCollection }, ({ issues, persons }) =>
1227 eq(issues.userId, persons.id)
1228 )
1229 .select(({ issues, persons }) => ({
1230 id: issues.id,
1231 title: issues.title,
1232 userName: persons.name
1233 }))
1234)
1235```
1236
1237```ts
1238// Handle loading and error states
1239const { data, isLoading, isError, status } = useLiveQuery((q) =>
1240 q.from({ todos: todoCollection })
1241)
1242
1243if (isLoading) return <div>Loading...</div>
1244if (isError) return <div>Error: {status}</div>
1245
1246return (
1247 <ul>
1248 {data.map(todo => <li key={todo.id}>{todo.text}</li>)}
1249 </ul>
1250)
1251```