Skip to content

Commit 355aa24

Browse files
committed
docs: 목차 바로가기 추가
1 parent 0e9dce6 commit 355aa24

1 file changed

Lines changed: 21 additions & 2 deletions

File tree

README.md

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,14 +35,14 @@
3535
- [useQuery 주요 리턴 데이터](#usequery-주요-리턴-데이터)
3636
- [v4부터는 status의 idle 상태값이 제거되고 fetchStatus가 추가](#v4부터는-status의-idle-상태값이-제거되고-fetchstatus가-추가)
3737
- [v4부터는 왜 status, fetchStatus 나눠서 다루는 걸까?](#v4부터는-왜-status-fetchstatus-나눠서-다루는-걸까)
38+
- [cacheTime과 staleTime중 어떤 값을 더 크게 해야할까?](#cachetime과-staletime-중-어떤-값을-더-크게-해야할까)
3839
- [useQuery 주요 옵션](#usequery-주요-옵션)
3940
- [staleTime과 cacheTime](#staletime과-cachetime)
4041
- [refetchOnMount](#refetchonmount)
4142
- [refetchOnWindowFocus](#refetchonwindowfocus)
4243
- [Polling](#polling)
4344
- [enabled refetch](#enabled-refetch)
4445
- [retry](#retry)
45-
- [onSuccess onError onSettled](#onsuccess-onerror-onsettled)
4646
- [select](#select)
4747
- [keepPreviousData](#keeppreviousdata)
4848
- [placeholderData](#placeholderdata)
@@ -175,6 +175,8 @@ import { ReactQueryDevtools } from "react-query/devtools";
175175

176176
### options
177177

178+
[목차 이동](#주요-컨셉-및-가이드-목차)
179+
178180
- initialIsOpen (Boolean)
179181
- `true`이면 개발 도구가 기본적으로 열려 있도록 설정할 수 있다.
180182
- position?: ("top-left" | "top-right" | "bottom-left" | "bottom-right")
@@ -186,6 +188,8 @@ import { ReactQueryDevtools } from "react-query/devtools";
186188

187189
### v4
188190

191+
[목차 이동](#주요-컨셉-및-가이드-목차)
192+
189193
- v4부터는 devtools를 위한 별도의 패키지 설치가 필요하다.
190194

191195
```bash
@@ -370,6 +374,8 @@ const { status, isLoading, isError, error, data, isFetching, ... } = useQuery(
370374

371375
### v4부터는 status의 idle 상태값이 제거되고 fetchStatus가 추가
372376

377+
[목차 이동](#주요-컨셉-및-가이드-목차)
378+
373379
- TanStack Query(v4) 부터는 status의 `idle이 제거`되고, 새로운 상태값인 `fetchStatus`가 추가됐다.
374380
- fetchStatus
375381
- fetching: 쿼리가 현재 실행중이다.
@@ -380,6 +386,8 @@ const { status, isLoading, isError, error, data, isFetching, ... } = useQuery(
380386

381387
### v4부터는 왜 status, fetchStatus 나눠서 다루는 걸까?
382388

389+
[목차 이동](#주요-컨셉-및-가이드-목차)
390+
383391
- fetchStatus는 HTTP 네트워크 연결 상태와 좀 더 관련된 상태 데이터이다.
384392
- 예를 들어, status가 `success` 상태라면 주로 fetchStatus는 `idle` 상태지만, 백그라운드에서 re-fetch가 발생할 때 `fetching` 상태일 수 있다.
385393
- status가 보통 `loading` 상태일 때 fetchStatus는 주로 `fetching`를 갖지만, 네트워크 연결이 되어 있지 않은 경우 `paused` 상태를 가질 수 있다.
@@ -392,7 +400,10 @@ const { status, isLoading, isError, error, data, isFetching, ... } = useQuery(
392400

393401
<br />
394402

395-
### `cacheTime``staleTime`중 어떤 값을 더 크게 해야할까?
403+
### cacheTime과 staleTime 중 어떤 값을 더 크게 해야할까?
404+
405+
[목차 이동](#주요-컨셉-및-가이드-목차)
406+
396407
- `cacheTime`의 기본값은 `300000ms`, 즉 5분이다.
397408
- `staleTime`의 기본값은 `0ms`, 즉 0초이며, 이는 한번 fetch 된 데이터는 기본적으로 곧바로 `stale` 상태가 되는 것이다.
398409
- 만약 `staleTime``cacheTime`보다 큰 값을 가지게 되면 어떻게 될까? 만약 `staleTime``10분`, `cacheTime``5분`이라고 가정해보자.
@@ -411,6 +422,8 @@ const { status, isLoading, isError, error, data, isFetching, ... } = useQuery(
411422

412423
### staleTime과 cacheTime
413424

425+
[목차 이동](#주요-컨셉-및-가이드-목차)
426+
414427
- stale은 용어 뜻대로 `썩은` 이라는 의미이다. 즉, 최신 상태가 아니라는 의미이다.
415428
- fresh는 뜻 그대로 `신선한` 이라는 의미이다. 즉, 최신 상태라는 의미이다.
416429

@@ -977,6 +990,8 @@ try {
977990
978991
### mutate와 mutateAsync는 무엇을 사용하는게 좋을까?
979992
993+
[목차 이동](#주요-컨셉-및-가이드-목차)
994+
980995
- 대부분의 경우 우리는 mutate를 사용하는 것이 유리하다. 왜냐하면 mutate는 콜백(onSuccess, onError)를 통해 data와 error에 접근할 수 있기 때문에 우리가 특별히 핸들링 해 줄 필요가 없다.
981996
- 하지만 mutateAsync는 Promise를 직접 다루기 때문에 이런 에러 핸들링 같은 부분을 직접 다뤄야한다.
982997
- 만약 이를 다루지 않으면 `unhandled promise rejection` 에러가 발생 할 수 있다.
@@ -1317,6 +1332,8 @@ const useSuperHeroData = (heroId: string) => {
13171332
13181333
### useQuery
13191334
1335+
[목차 이동](#주요-컨셉-및-가이드-목차)
1336+
13201337
현재 useQuery가 갖고 있는 제네릭은 `4`이며, 다음과 같다.
13211338
13221339
1. TQueryFnData: useQuery로 실행하는 query function의 `실행 결과`의 타입을 지정하는 제네릭 타입이다.
@@ -1357,6 +1374,8 @@ const { data } = useQuery<
13571374

13581375
### useMutation
13591376

1377+
[목차 이동](#주요-컨셉-및-가이드-목차)
1378+
13601379
useMutation도 useQuery와 동일하게 현재 4개이며, 다음과 같다.
13611380
1. TData: useMutaion에 넘겨준 mutation function의 `실행 결과`의 타입을 지정하는 제네릭 타입이다.
13621381
- data의 타입과 onSuccess(1번째 인자)의 인자의 타입으로 활용된다.

0 commit comments

Comments
 (0)