const promise = fetch(url [, options])
<사용법>
npm i axios
import axios from 'axios';
useEffect(() => {
axios.get('https://api.example.com/data')
.then(response => setData(response.data))
.catch(error => console.error('Error:', error));
}, []);
const url = '요청할 주소'
const options = {
method: 'POST',
header: {
'Accept' : 'application/json',
'Content-Type':'application/json';charset=UTP-8'
},
body:JSON.stringify({
name: 'test'
})
fetch(url.options)
.then(response => console.log(response))
}
url = '요청할 주소'
method:'POST',
header: {
'Accept':'application/json',
'Content-Type': 'application/json';charset=UTP-8'
},
data: {
name: 'test'
}
axios(options)
.then(response => console.log(response))
}

<React Query라는 이름으로 시작했지만, v4부터 Vue나 Svelte 등의 다른 프레임워크에서도 활용할 수 있도록 기능이 확장되며 TanStack Query라는 이름으로 변경되었다.>
<데이터 캐싱>
어.. 더 쓰려고 했는데 생각보다 길어져서 따로 TanStack Query에 대한 포스팅을 해볼게요
import { useQuery } from '@tanstack/react-query'
export default function DelayedData() {
const { data } = useQuery({
queryKey: ['delay'],
queryFn: async () => (await fetch('https://api.heropy.dev/v0/delay?t=1000')).json()
})
return <div>{JSON.stringify(data)}</div>
}
4번은 진짜 처음 봤는데
GraphQL (Apollo Client / Relay)는 GraphQL API를 사용하는 프로젝트에 적합한 클라이언트 라이브러리로 데이터 요청을 효율적으로 구성,프런트엔드에서 필요한 데이터만 요청 가능하며 데이터 요청에 최적화 되어있으나 GraphQL API 환경 필요하다.
Redux Middleware (Thunk, Saga 등)는 Redux 상태 관리와 API 통합한다. 비동기 작업 처리를 위해 Thunk 또는 Saga 사용하고 상태와 API 요청 로직을 통합 관리하며 전역 상태와 API 요청 통합하지만 설정 및 코드 복잡도 증가한다..
to be continue..