Problem Statement
How to integrate APIs (fetch or axios) in functional components?
Explanation
Call the API inside useEffect after the first render, update state with results, and handle errors gracefully. Axios simplifies HTTP requests and error handling.
Code Solution
SolutionRead Only
useEffect(()=>{axios.get('/api').then(r=>setData(r.data)).catch(e=>setError(e));},[]);Practice Sets
This question appears in the following practice sets: