Using Hooks and React Suspense for Data Fetching
In the previous chapter, we learned how to use React Context as an alternative to manually passing down props. We learned about context providers, consumers and the Context Hook.
In this chapter, we are going to first set up a simple backend server from a JSON file using the json-server
tool. Then, we are going to fetch data from our server using an Effect Hook in combination with a State Hook. Next, we are going to do the same using TanStack Query, a popular data fetching library for React that makes use of Hooks. Finally, we will learn about React Suspense, which can be used to defer rendering until the content has finished loading.
The following topics will be covered in this chapter:
- Setting up a simple backend server
- Requesting resources using an Effect and a State Hook
- Using TanStack Query to request resources and make changes
- Introducing React Suspense and Error Boundaries