fetch data loop in react native code example
Example: react fetch data in for loop
videoUrls=()=>{
let i=0;
let urllist=[]
for(i;i< this.state.data.length;i++){
fetch(`https://www.googleapis.com/youtube/v3/search?part=snippet&q=${this.state.data[i].name}&key=xxxxxxxxxxx0`)
.then(response=> {
return response.json()
})
.then(data=>{
return(urllist.push(data.items[0]))
})
}
console.log({urllist})
}
videoUrls = async () => {
let i=0;
let urllist=[]
for(i;i< this.state.data.length;i++){
const response = await fetch(`https://www.googleapis.com/youtube/v3/search?part=snippet&q=${this.state.data[i].name}&key=xxxxxxxxxxx0`)
const json = await response.json()
urllist.push(json.items[0])
console.log({urllist})
}
}