There is an API of friends, and with such code the code endlessly loops, I think this is due to the fact that I do not stop the transmission of responce.result, but I do not know how to fix it
function FriendsAPI(){
const [items, setItems] = useState([1,2,3,4,5,6])
const [loading, setLoading] = useState(false)
useEffect (() =>{
fetch("https://randomuser.me/api/?results=6&nat=US")
.then((response) => response.json())
.then((response) => {
setItems(response.results)
setLoading(true)
})
})
if(!loading){
return (
<div>Loading ...</div>
)
}
else {
return (
<div className={classes.WrapperImage}>
{console.log('render')}
{ items.map((item, index) => (
<div className={classes.Pictures} key={index}>
<img src={item.picture.medium} alt={item.name.first} className={classes.Img}/>
<p>{item.name.first}</p>
</div>
)) }
</div>
)
}
}
useEffect(() => { /* ... */ }, [])