Background: I was trying to fetch all the links for a set of images, then fetch the real assets for images using the links fetched.
let imageLinks = [];
useEffect(() => {
fetch("http://localhost:3001/video/1?offset=0&count=100")
.then((res) => res.json())
.then((res) => {
imageLinks = res.frames;
});
}, []);
useEffect(() => {
Promise.all(
imageLinks.map((link) =>
fetch("http://localhost:3001/" + link).then((res) => res.json())
)
).then((res) => console.log(res));
// update when the image links changed
}, [imageLinks]);
The last useEffect didn't seem to be working, even when imageLinks has been updated in the previous useEffect. Could anyone please tell me why is that?