- Install the below axios package to make the api call
npm i axios
- Following open API is being used to fetch the user list.
- Setup the base api for the common changes.
src/utility/services/base.ts
- Get API service call.
src/utility/services/user.ts
- User Hook: src/hook/user.ts
This is the user hook to load the user data by making api call. It handle errors using try, catch and finally block. We can reuse this hook anywhere in the application whenever we need user list.
hsharmacoding / 9-react-axios-api-call Goto Github PK
View Code? Open in Web Editor NEWShow the user list from the API using Axios library.