skip to Main Content

Reactjs – Cleanup function after a fetch call in React

const[imageContainer,setImageContainer] = useState([]) const navigate = useNavigate(); useEffect(()=>{ Promise.all([ fetch("https://www.themealdb.com/api/json/v1/1/random.php").then(response=>response.json()), fetch("https://www.themealdb.com/api/json/v1/1/random.php").then(response=>response.json()), fetch("https://www.themealdb.com/api/json/v1/1/random.php").then(response=>response.json()), fetch("https://www.themealdb.com/api/json/v1/1/random.php").then(response=>response.json()), fetch("https://www.themealdb.com/api/json/v1/1/random.php").then(response=>response.json()), ]).then(response=>setImageContainer(response.map(recipe=>{ return recipe.meals[0] }))) },[]) Hello, I'm relatively new to React. So far I've learned that you should always clean up after using useEffect with the…

VIEW QUESTION
Back To Top
Search