Fetch data from API in ReactJS
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.
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 axios
Axios making HTTP requests from a browser or node.js. It returns a Promise that resolves to the response object.
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.