-
Notifications
You must be signed in to change notification settings - Fork 3
Custom API Hook
André Kovac edited this page Oct 6, 2021
·
1 revision
- Clone the
PhotoFavoriterepository from https://github.com/andrekovac/PhotoFavorite if not done yet. - Run
git switch 04-custom-hook-for-api-callto switch to the04-custom-hook-for-api-callbranch, in fact this state: https://github.com/andrekovac/PhotoFavorite/tree/04-custom-hook-for-api-call
- You'll notice a small difference to the result of the previous task: The
PhotosScreennow contains aPhotoListcomponent which fetches the photos and renders the list.
The current state of the app contains a custom hook.
-
Observe the diff where the custom hook
useDataApiwas added: https://github.com/andrekovac/PhotoFavorite/commit/49d8855131aaf1ea45e759d0cdedec03dad58d9c- How does this custom hook generalize API calls.
- How is it assured that a new fetch will take place whenever the
urlprovided to theuseDataApihook changes? What is the crucial line number inuseDataApi.ts?
- Observe the file https://github.com/andrekovac/PhotoFavorite/blob/04-custom-hook-for-api-call/src/hooks/useDataApi.ts
Question: What is the crucial line number in useDataApi.ts?
Answer: 34