728x90
반응형
Axios
https://github.com/axios/axios
GitHub - axios/axios: Promise based HTTP client for the browser and node.js
Promise based HTTP client for the browser and node.js - GitHub - axios/axios: Promise based HTTP client for the browser and node.js
github.com
- fetch의 문제점
데이터를 받아와서 respond를 json 형태로 변환 해줘야함
then 안에 오류가 혼재되어 있음
이러한 문제점들을 보완 해줄 수 있는게 axios
- 사용방법
라이브러리 추가
yarn add axios
임포트 해주기
import axios from 'axios'
async () => {
axios.get('/videos/')
.then((res) => res.data.items);
}
네트워크 통신 뿐만 아니라 백엔드에서 데이터를 받아오지 못하는 경우 catch에서 걸러줌
then에서는 데이터를 성공적으로 받아오는 경우만 작동
728x90
'Frontend > React' 카테고리의 다른 글
[Error] Property 'id' does not exist on type 'never' 타입스크립트 에러 (0) | 2022.12.22 |
---|---|
[Redux] 리덕스 기본 개념 (2) | 2022.12.20 |
[React] 라우팅, CSR 개념 (0) | 2022.12.13 |
[React] 리액트 쿼리 React Query (0) | 2022.12.11 |
[React] 컴포넌트의 재사용성 {children} (0) | 2022.12.09 |