This url http://127.0.0.1:5051/load/ will return list of values (Example:list_val =['a','b','c','d']). For each value in the list an api(http://127.0.0.1:5051/sample/"+**list_val[i]**+"/version) is called and the response of all the api should be assigned to the state variable. How can I achieve this ? Should I create a list and push the response of each api to the list and then set the state ?
componentDidMount(){
fetch("http://127.0.0.1:5051/load/")
.then(response =>{
return response.json();
})
.then(data => {
let fromapi = data
var version_len = fromapi.length;
for (var i=0; i<version_len; i++){
//console.log(fromapi[i])
fetch("http://127.0.0.1:5051/sample/"+fromapi[i]+"/version")
.then(response =>{
return response.json();
})
.then(data=>{
let version_api = data
console.log(version_api)
this.setState({
version : version_api
})
})
}
})
.catch(error=>{
console.log(error);
})
}