9

Interacting with RESTful APIs

In this chapter, we will build a page that lists blog posts fetched from a REST API, as well as also a form to submit blog posts to the REST API. Through this, we will learn about various approaches to interacting with a REST API from a React component.

The first approach will be using React’s useEffect hook with the browser’s fetch function. As part of this process, we learn how to use a type assertion function to strongly type the data from a REST API. We will then use the data loading capability of React Router and experience its benefits. After that, we will move on to use a popular library called React Query and experience its benefits, before using React Query and React Router together to get the best of ...

Get Learn React with TypeScript - Second Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.