async wait 사용하기
componentDidMount() {
const getPostListAndTags = async () => {
const postsData =
fetch(getListUrl(this.state.numberOfLists, this.state.sortingBy, 0))
.then(res => res.json())
.then(listsData => listsData);
const tagsPata =
fetch('/api/v1/tags')
.then(res => res.json())
.then(tagsData => tagsData);
const postsDataResult = await postsData;
const tagsPataResult = await tagsPata;
return [postsDataResult, tagsPataResult];
}
getPostListAndTags().then(results => {
const [listsData, tagsData] = results;
this.setState({
listDataOfArticles: listsData.posts,
dataOfTags: tagsData,
nextPageIndex: 1,
});
});
}참고 예시
Last updated