DEV Community

Augustine Victor
Augustine Victor

Posted on

How to create a reusable API service client in react using FETCH.

This article will be useful to you if you are like me who doesn't rely much on third party libaries. Let's begin:

I will be using a mini project for this demo.
Project structure
1. Create a new react app using vite or CRA but I will be making use of Typescript.

2. In the service folder we added the API service client.
API Client

3. In the hooks folder we make use of the API Client we created earlier.
Custom hook for API Client

4. And finally we make use of our custom hook in our components.
Using custom hooks in component
This is not a principle but a concept you can apply in your project.

Github repo

Top comments (0)