fetch API는 보통 이렇게 GET 요청을 하는데
fetch(url)
.then((response) => response.json())
.then(console.log);
axios 라이브러리는 이렇게 GET 요청을 할 수 있다.
axios.get('/user?ID=12345')
.then(function (response) {
// handle success
console.log(response);
})
.catch(function (error) {
// handle error
console.log(error);
})
.finally(function () {
// always executed
});
axios는자동으로 JSON 데이터를 Array나 Object로 변환해주는 반면 fetch API 는 .json()으로 변환한다
또한 fetch가 axios보다 조금 빠르다고 한다.
'React' 카테고리의 다른 글
avoid using useEffect (0) | 2023.09.20 |
---|---|
뜨거운 SSR은 가고 남은 건 볼품없지만 (feat. SSG, CSR, ISR) (0) | 2023.09.05 |
FSD (Feature-Sliced Design) (0) | 2023.08.29 |
왜 클래스형이 아닌 react hooks일까? (0) | 2022.07.24 |
리액트가 무엇일까? (0) | 2022.07.22 |
댓글