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
Copy file name to clipboardExpand all lines: README.md
+16-7Lines changed: 16 additions & 7 deletions
Original file line number
Diff line number
Diff line change
@@ -39,19 +39,19 @@ Let's say the data doesn't change that often. We can set the stale time to 30 se
39
39
40
40
0 seconds is possibly the safest value you can set to stale time, which is also the default value.
41
41
42
-
3. react-query refetchOnMount
42
+
**3. react-query refetchOnMount**
43
43
44
44
If set to true, the query will refetch on mount if the data is stale. If set to false, will disable additional instances of a query to trigger background refetches. If set to 'always', the query will always refetch on mount. If set to a function, the function will be executed with the latest data and query to compute the value Defaults to true.
45
45
46
46
Default value is set to true.
47
47
48
-
4. react-query refetchOnWindowFocus
48
+
**4. react-query refetchOnWindowFocus**
49
49
50
50
If set to true, the query will refetch on window focus if the data is stale. If set to false, the query will not refetch on window focus. If set to 'always', the query will always refetch on window focus. If set to a function, the function will be executed with the latest data and query to compute the value. Defaults to true.
51
51
52
52
Default value is set to true.
53
53
54
-
5. react-query refetchInterval - Polling
54
+
**5. react-query refetchInterval - Polling**
55
55
56
56
Fetching data at regular intervals. For example: If you have component that shows real time price of different stocks, you might want to fetch the data every second so is in sync with UI.
57
57
@@ -61,24 +61,33 @@ Default value is set to false.
61
61
62
62
Polling is paused when the window lose focus. To fix that issue we can set `refetchIntervalInBackground` property to true.
63
63
64
-
6. Homework (Solution on branch: feature/09-homework)
64
+
**6. Homework (Solution on branch: feature/09-homework)**
65
65
66
66
Combine polling with callbacks. Use the `refetchInterval` option to pull the api data every 3 seconds. Behind the scenes add a fourth superhero of your choice to the superheroes array in `db.json`.
67
67
68
-
a.) Within the onSuccess callback check if the number of heroes is 4 and ifit is the case I want you to stop the polling.
69
-
b.) Within the onError callback I want you to stop the polling.
68
+
a.) Within the onSuccess callback check if the number of heroes is 4 and ifit is the case I want you to stop the polling.
69
+
b.) Within the onError callback I want you to stop the polling.
70
70
71
71
Hint:
72
72
Mantain state variable whose initial value is 3000. State variable will be assigned to `refetchInterval` configuration. In callbacks check for the response / errors and set the state variable to false.
73
73
74
-
7. react-query select - Data Transformation
74
+
**7. react-query select - Data Transformation**
75
75
76
76
For data tranformation react-query provides us with `select` flag.
77
77
78
78
`select` is function that receives onSuccess response and transform out data in the way we want it.
79
79
80
80
In our example we transformed data to be an array of just heroes names instead of whole response.
81
81
82
+
**8. QueryById - 2 solutions**
83
+
84
+
We can query by id in two ways (look commits under branch name: `feature/12-queryById`).
85
+
86
+
a.) Solution 1 or first commit: **QueryById with manuali passed ID**
87
+
- We can manually pass id into fetch function: file `useSuperHeroData`
88
+
b.) Solution 2 or second commit: **QueryById with react-query automatic passed id**
89
+
- React query automatically pass id into fetch function: file `useSuperHeroData`
0 commit comments