0
我想返回由函數getData()獲取的數據並使用返回的值(return this.getStreamer(values[0],values[1]);
)來呈現StreamerContainerResult
組件。我想獲取數據返回某個值的函數
然而,它保留返回「不確定」,因此,我不能使任何東西..
我被困在這個bug在過去的幾個小時,我無法弄清楚我自己。
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...')
});
}
https://codepen.io/brood915/pen/OWQpmy?editors=0110
謝謝。我成功地訪問了函數返回的元素。但是,由於某些原因,它仍然不會被組件渲染。爲什麼? – brood915
你正在使用reactJS呃?我不太瞭解它..但也許這[問題](http://stackoverflow.com/questions/24185029/reactjs-async-wait-for-results)將有所幫助。乾杯。 – matt