I am trying to return the data fetched by the function getData() and use the returned value (return this.getStreamer(values[0],values[1]);
) to render the StreamerContainerResult
component.
However, it keeps returning "undefined" and as a result, I cant render anything..
I am stuck on this bug for the past few hours and I cant figure it out on my own.
getData(value, type) {
let streamerData = [];
let urls = ['https://wind-bow.gomix.me/twitch-api/streams/' + value, 'https://wind-bow.gomix.me/twitch-api/users/' + value];
const getJson = url => fetch(url).then(res => res.json());
Promise.all(urls.map(getJson))
.then((values) => {
if (type === "search") {
this.setState({
streamer: values
});
console.log("searching");
} else {
console.log("displaying");
return this.getStreamer(values[0],values[1]);
}
}).catch(err => {
console.log('Something went wrong...')
});
}