i have a component that gets all products via fetch. it returns all of the products, but then i use a second fetch to get more data based on what was retrieved with the first fetch:
const [products, setProducts] = useState([]);
const [productImages, setProductImages] = useState([]);
useEffect(() => {
fetch(state.source.api + "/wp/v2/product")
.then((response) => response.json())
.then((data) => {
setProducts(data); //set state
//loop through each data to get featured_media number
data.forEach((item) => {
//get all urls using featured_media
fetch(state.source.api + "/wp/v2/media/"+ item.featured_media)
.then((response) => response.json())
.then((o) => {
//get all urls OR store to react State
console.log(o.source_url)
});
})
});
}, []);
console.log(productImages);
I am confused on how to set the values of o.source_url
into const [productImages, setProductImages] = useState([]);
Can someone please help me out with this? I can provide more code if that is needed.