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
-[ ] Add a `QueryClientProvider` and wrap the application entry point.
71
79
72
-
**🔭 Hint:** You can have a look at the [`QueryClientProvider` documentation](https://tanstack.com/query/v4/docs/reference/QueryClientProvider)
80
+
**🔭 Hint:** You can have a look at the [`QueryClientProvider` documentation](https://tanstack.com/query/latest/docs/framework/react/reference/QueryClientProvider#queryclientprovider)
73
81
74
82
### Fetching resources across the network
75
83
76
-
-[ ] Take 5 min to **read carefully** the [`useQuery` documentation](https://tanstack.com/query/v4/docs/guides/queries).
77
-
78
-
In the example `useQuery`, `isLoading` and `isError` lives on the same files.
79
-
80
-
To have a more robust application, and separte the concerns of the data and the ui, we can wrap our queries into one custom hook `useStarships()`.
84
+
-[ ] Take 5 min to **read carefully** the [`useQuery` documentation](https://tanstack.com/query/latest/docs/framework/react/guides/queries).
81
85
82
86
The logic is:
83
87
84
88
1.`fetch` data from the endpoint and return the result as a `json`
85
89
1. Get the result from the fetch and return the result of `useQuery`
86
-
1. Use our custom hook to render the UI
90
+
1. render the UI
91
+
92
+
Using the `useQuery` hook and `fetchStarshipsData`, fetch data from the Star Wars API:
thrownewError("Something bad happened with the api…");
102
+
}
103
+
}
104
+
```
105
+
106
+
-[ ] Use the hook to **dislay a loading message**.
107
+
-[ ] Use the hook to **handle errors**.
108
+
-[ ] Use the hook to replace `data.json` and **render data** with a `FlatList`.
109
+
110
+
## 👽 Bonus
111
+
112
+
In the previous challenge `useQuery`, `isPending` and `isError` lives on the same files. To have a more robust application, and separte the concerns of the data and the ui, we can wrap our queries into one custom hook `useStarships()`.
87
113
88
114
-[ ] Create a new file `useStarships.ts` and paste the content bellow
Now you can write `useStarships()` anywhere in your Screen and React Query handles the rest.
106
136
107
-
-[ ] Go to your Feed screen and remplace the `data.json` with data from the swapi.
108
-
-[ ] Use `useStarships` hook to **dislay a loading message**.
109
-
-[ ] Use `useStarships` hook to **handle errors**.
110
-
-[ ] Use `useStarships` hook to **render data** with a `FlatList`.
111
-
112
137
If you want to display some images on your `Card`, you can use this placeholder `https://picsum.photos/400/200` as a `source`.
113
138
114
-
## 👽 Bonus
115
-
116
139
-[ ] Save this talk to your "Watch later" playlist: [Custom Hooks in React: The Ultimate UI Abstraction Layer](https://www.youtube.com/watch?v=J-g9ZJha8FE) from Tanner Linsley
117
140
-[ ] Display a nice animated placeholder during loading with [rn-placeholder](https://github.com/mfrachet/rn-placeholder)
118
141
-[ ] Add a "Pull to Refresh" functionality to your FlatList with `onRefresh`
0 commit comments