I am learning the react hooks and i used the random API for fetching the demo users. can anyone told me why the hello is printed 6 times and also i am not able to use the if statement inside my return statement
import React, {useState, useEffect} from "react";
function RandomUser () {
const [users, setuser] = useState([]);
const [loading, setLoading ] = useState(true);
useEffect(()=>{
console.log("fetching api ");
fetch("https://randomuser.me/api/?results=50").then((res)=>{
return res.json();
}).then((res)=>{
setuser(res.results);
setLoading(false);
})
},[])
console.log("hello");
return (
<>
{loading && <h1>Loading</h1>}
{users.map((v,i)=>{
return(
<li>
{v.name.first}
</li>
)
})}
</>
);
}
export default RandomUser;