React
React - fetch cors 문제 해결
soksok
2020. 9. 6. 17:35
반응형
nodeJS 없이 React만으로 fetch로 API를 받아오는 중 cors문제가 발생했다.
이를 해결하기 위해서는 다음과 같이 작성하여 fetch를 받아오자
const proxyurl = "https://cors-anywhere.herokuapp.com/";
const url = "API 주소";
fetch(proxyurl + url)
.then(response => response.json())
.then(contents => setStatsInfo({stats:contents}))
.catch(() => console.log("stats 데이터를 가져오는데 실패했습니다."))
}
반응형