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
+17-5Lines changed: 17 additions & 5 deletions
Original file line number
Diff line number
Diff line change
@@ -1,6 +1,6 @@
1
1
# React Query tutorial
2
2
3
-
Tutorial videos from made by [Codevolution](https://www.youtube.com/watch?v=Ev60HKYFM0s&list=PLC3y8-rFHvwjTELCrPrcZlo6blLBUspd2&index=3).
3
+
Tutorial videos are made by [Codevolution](https://www.youtube.com/watch?v=Ev60HKYFM0s&list=PLC3y8-rFHvwjTELCrPrcZlo6blLBUspd2&index=3).
4
4
5
5
Code is separated with different branches. Every video has his own branch.
6
6
@@ -16,7 +16,9 @@ Code is separated with different branches. Every video has his own branch.
16
16
17
17
## About react-query
18
18
19
-
1. react-query cache
19
+
Link to [offical website](https://react-query.tanstack.com/).
20
+
21
+
**1. react-query cache**
20
22
21
23
The first time useQuery is fired for superheros key, isLoading flag is set to true and network request is send to fetch the data. When the request is completed it is cached used the query key (superheroes) and the fetchSuperHeroes function as the unique identifiers.
22
24
@@ -31,7 +33,7 @@ React query cache the data so we don't need to see the loading indicator every t
31
33
32
34
The default cache time is set to 5 mintes. We can change it with options cacheTime property
33
35
34
-
2. react-query stale time
36
+
**2. react-query stale time**
35
37
36
38
Let's say the data doesn't change that often. We can set the stale time to 30 seconds and the user will see the cached query results or cached data for 30 seconds before refetching it again. The default state time is set to 0 seconds.
37
39
@@ -49,7 +51,7 @@ If set to true, the query will refetch on window focus if the data is stale. If
49
51
50
52
Default value is set to true.
51
53
52
-
5. react-query polling
54
+
5. react-query refetchInterval - Polling
53
55
54
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.
55
57
@@ -59,7 +61,17 @@ Default value is set to false.
59
61
60
62
Polling is paused when the window lose focus. To fix that issue we can set `refetchIntervalInBackground` property to true.
61
63
62
-
6. react-query select - Data Transformation
64
+
6. Homework (Solution on branch: feature/09-homework)
65
+
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
+
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
+
71
+
Hint:
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
+
74
+
7. react-query select - Data Transformation
63
75
64
76
For data tranformation react-query provides us with `select` flag.
0 commit comments