Click here to Skip to main content
15,881,709 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
When I console.log it only gives me one object and im guessing its because of the way I've deconstructed it. setAgent is iterating over a single object instead of the array of objects. But im not sure how to fix this.

useEffect(() => {
  async function fetchData() {
    const response = await fetch(`https://randomuser.me/api/?results=10`);
    const data = await response.json();
    const [item] = data.results;
    setAgent(item);
    console.log(item);
  }
  fetchData();
},[]);


What I have tried:

I tried using setAgent(data); but it gives me an uncaught type error
Posted
Comments
Afzaal Ahmad Zeeshan 14-May-21 18:16pm    
Try to print the data variable.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900