Problem Statement
How do you handle API calls in React (Fetch, Axios, React Query)?
Explanation
Fetch and Axios are used for HTTP requests. React Query helps manage server state with caching, auto refetching, and error handling. Always handle loading and error states during fetch operations.
Code Solution
SolutionRead Only
useEffect(() => {
fetch('/api/data')
.then(res => res.json())
.then(setData)
.catch(console.error);
}, []);Practice Sets
This question appears in the following practice sets: