Fetch data from API in ReactJS

Fetch data from API in ReactJS


fetch api data


Using aync-await and custom useFetch() Hook

Custom hook that takes in a URL and options object, sends a GET request to the URL using the fetch API, and returns an object isLoading, data and error.


aync-await fetch data from API

fetch-api

render html element with loop

Using fetch

The Fetch API is a built-in browser API, including data from a server. It returns a Promise that resolves to the response object.

using fetch to get api data


display data of API

Using axios

Axios making HTTP requests from a browser or node.js. It returns a Promise that resolves to the response object.


axios to get api data


axios data display


Using react-query

Returns an object that contains isLoading, error, and data.


isLoading: Boolean that is true while the query is loading data from the API.

error: Any error that occurred while fetching the data.

data: The data that was fetched from the API. 


react-query to fetch data


react-query to fetch data display











Previous Post Next Post