[Axios] Axios interceptor와 react-spinners를 사용하여 로딩 중 상태 구현하기


[Axios] Axios interceptor와 react-spinners를 사용하여 로딩 중 상태 구현하기

Axios에는 인터셉터라는 것이 존재한다. 이는 서버에 요청이 전달되기 전과 서버로부터 응답을 받을 때 가로채서 특정 동작을 수행하도록 하기 위해 존재한다. 인터셉터와 react-spinners 라이브러리를 사용하여 api 요청을 할 때 로딩 중인 상태를 알 수 있도록 로딩바를 구현해보자. 아래 나올 코드는 이전 글과 이어지는 코드이다. [Axios] Axios 인스턴스 생성하기 지금까지 axios를 사용할 때는 아래와 같이 사용했다. const url = "https://jsonplaceholder.typicode.com/"; const getInfo = () => { axios .get(url + "posts") .then((res) => { console.log(res); }) .catch((e) ..


원문링크 : [Axios] Axios interceptor와 react-spinners를 사용하여 로딩 중 상태 구현하기