skip to Main Content

How to stop infinite loop in setState – Javascript

const cats = [ 1, 2, 3 ]; let arr = []; const [images, setImages] = useState([]); const generateCat = () => { fetch( "https://api.thecatapi.com/v1/images/search?size=small&limit=1&mime_types=jpg,png&width=200&height=200" ) .then(response=>{return response.json()}) .then(data=>{ let finalResult = data[0]['url'] arr.push(finalResult) console.log(arr) return finalResult }) }; for(let…

VIEW QUESTION
Back To Top
Search