You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The `useQuery` hook returns a stateful object which contains query fetching/loading state values and the query result set data.
278
278
@@ -294,21 +294,23 @@ The returned object is a new JS object reference whenever the internal state cha
294
294
function MyWidget() {
295
295
// ... Widget code
296
296
// result is an object which contains `isLoading`, `isFetching`, `data` members.
297
-
constresult=useQuery(...)
297
+
const{data, error, isLoading}=useQuery(...)
298
298
299
299
// ... Widget code
300
300
301
301
return (
302
-
// Other components
303
-
// MyWatchedWidget will rerender whenever the watched query state changes
304
-
// (MyWatchedWidget will also rerender if the result object is unchanged if it is not memoized)
305
-
<MyWatchedWidgetwatchedResult={result}>
302
+
// ... Other components
303
+
304
+
// If MyWatchedWidget is not memoized
305
+
// - It will rerender on any state change of the watched query. E.g. if isFetching alternates
306
+
// If MyWatchedWidget is memoized
307
+
// - It will re-render if the data reference changes. By default the data reference changes after any
308
+
// change to the query's dependant tables. This can be optimized by using Incremental queries.
309
+
<MyWatchedWidgetwatchedResult={data}>
306
310
)
307
311
}
308
312
```
309
313
310
-
The above example is incomplete, but is required for the optimizations below.
311
-
312
314
### Incremental Queries
313
315
314
316
By default watched queries are queried whenever a change to the underlying tables has been detected. These changes might not be relevant to the actual query, but will still trigger a query and `data` update.
@@ -372,7 +374,7 @@ function MyWidget() {
372
374
// The `data` reference will only be changed if there have been changes since the previous value.
373
375
// When reportFetching == false the object returned from useQuery will only be changed when the data, isLoading or error state changes.
374
376
// This method performs a comparison in memory in order to determine changes.
375
-
const { data, isLoading, isFetching } =useQuery(`SELECT * FROM cats WHERE breed = 'tabby'`, [], {
377
+
const { data, isLoading } =useQuery(`SELECT * FROM cats WHERE breed = 'tabby'`, [], {
376
378
processor: {
377
379
mode: 'comparison',
378
380
comparator: newArrayComparator({
@@ -388,7 +390,6 @@ function MyWidget() {
388
390
// Other components
389
391
// The data array is the same reference if no changes have occurred between fetches
390
392
// Note: The array is a new reference is there are any changes in the result set (individual row object references are not preserved)
391
-
// Note: CatCollection requires memoization in order to prevent re-rendering (due to the parent re-rendering on fetch)
0 commit comments