Notice
Recent Posts
Recent Comments
Link
250x250
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | ||||
4 | 5 | 6 | 7 | 8 | 9 | 10 |
11 | 12 | 13 | 14 | 15 | 16 | 17 |
18 | 19 | 20 | 21 | 22 | 23 | 24 |
25 | 26 | 27 | 28 | 29 | 30 | 31 |
Tags
- JSON
- foreach
- redux toolkit
- couchcoding
- 인라인블럭
- 자바스크립트
- 카우치코딩
- javascript코딩테스트
- first-child
- Redux store
- useSearchParams
- sort
- 자바스크립트배포
- 협업프로젝트
- db.json
- react
- javascript React
- line-through
- Redux
- useEffect
- 블럭요소
- react redux
- 콜백함수
- React state
- toString
- JavaScript
- React onClick
- 6주포트폴리오
- useParams
- redux 사용방법
Archives
- Today
- Total
개발하는 루루언니
Tanstack Query 사용해보기 본문
728x90
반응형
1. 설치하기 ( 사용하는걸로 )
npm i @tanstack/react-query
import { QueryClient, QueryClientProvider, useQuery } from '@tanstack/react-query'
const queryClient = new QueryClient()
export default function App() {
return (
<QueryClientProvider client={queryClient}>
<Example />
</QueryClientProvider>
)
}
function Example() {
const { isLoading, error, data } = useQuery({
queryKey: ['repoData'],
queryFn: () =>
fetch('https://api.github.com/repos/tannerlinsley/react-query').then(res =>
res.json()
)
})
if (isLoading) return 'Loading...'
if (error) return 'An error has occurred: ' + error.message
return (
<div>
<h1>{data.name}</h1>
<p>{data.description}</p>
<strong>👀 {data.subscribers_count}</strong>{' '}
<strong>✨ {data.stargazers_count}</strong>{' '}
<strong>🍴 {data.forks_count}</strong>
</div>
)
}
728x90
'컴퓨터 정보 > 리액트' 카테고리의 다른 글
useQuery 공식 (0) | 2022.11.12 |
---|---|
axios 공식 (0) | 2022.11.12 |
outlet 사용하는법 : 페이지 전체를 랜더링 X (0) | 2022.11.11 |
라우팅 vs 클라이언트 사이드 라우팅 (0) | 2022.11.11 |
npm 설치 : npm i @tanstack/react-query (0) | 2022.11.11 |