Summary
In this chapter, we learned about the useQuery custom hook and how it allows you to fetch and cache your data by using its required options, called query key and query function. You learned how to define your query key and how your query function allows you to use any data-fetching client such as GraphQL or REST, so long it returns a promise or throws an error.
You also learned about some of the things that the useQuery hook returns, such as the query’s data and error. For you to craft a better user experience, you were also introduced to status and fetchStatus.
For you to customize your developer experience and take it to the next level, you learned about some commonly used options you can use to customize your useQuery hook and make it behave as you want it to. For your convenience, here are the compiled defaults to be aware of:
staleTime: 0cacheTime: 5 * 60 * 1,000 (5 minutes)retry: 3retryDelay: Exponential backoff delay algorithm
...