Skip to content

Commit ccfd8b0

Browse files
committed
feat: v4 docs 내용 추가 개선
1 parent 7ba0531 commit ccfd8b0

File tree

1 file changed

+47
-0
lines changed

1 file changed

+47
-0
lines changed

README.v4.md

+47
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@
5555
28. [서버 로딩중일 때 Fallback UI를 선언적으로 보여주기 위한 Suspense](#suspense)
5656
29. [앱 전체에 동일한 쿼리 함수를 공유하는 Default Query Function](#default-query-function)
5757
30. [리액트 쿼리에 타입스크립트 적용](#react-query-typescript)
58+
31. [리액트 쿼리 지원 버전](#지원-버전)
5859

5960
<br />
6061

@@ -1516,3 +1517,49 @@ const { mutate } = useInfiniteQuery<Colors, AxiosError, Colors, ["colors"]>(
15161517
* getNextPageParam: GetNextPageParamFunction<Colors>
15171518
*/
15181519
```
1520+
1521+
<br />
1522+
1523+
### 💡 Typescript Best Practice
1524+
1525+
- [TypeScript 공식 문서](https://tanstack.com/query/v5/docs/react/typescript)
1526+
- 위의 제네릭을 모두 사용하는건 코드의 복잡도가 늘어난다. 하지만 react query는 타입을 잘 전달하므로 굳이 제네릭을 모두 직접 제공 할 필요가 없다.
1527+
- 가장 좋은 방법은 `queryFn`의 타입을 잘 정의해서 `타입 추론`이 원활하게 되게 하는 것이다.
1528+
1529+
```tsx
1530+
const fetchGroups = async (): Promise<{ data: Group[] }> => {
1531+
const res = await axios.get("/groups");
1532+
return res;
1533+
};
1534+
1535+
const { data } = useQuery(["groups"], fetchGroups, {
1536+
select: (data) => data.data,
1537+
});
1538+
1539+
/**
1540+
주요 타입
1541+
* data: Group[] | undefined
1542+
* error: Error | null
1543+
* select: (data: { data: Group[] }): Group[]
1544+
*/
1545+
```
1546+
1547+
<br />
1548+
1549+
## 지원 버전
1550+
1551+
[목차 이동](#주요-컨셉-및-가이드-목차)
1552+
1553+
- Tanstack Query v4에 필요한 TypeScript 최소 버전은 `v4.1` 입니다.
1554+
- Tanstack Query v4의 브라우저 별 지원 버전은 아래와 같습니다.
1555+
1556+
```
1557+
Chrome >= 73
1558+
Firefox >= 78
1559+
Edge >= 79
1560+
Safari >= 12.1
1561+
iOS >= 12.2
1562+
Opera >= 53
1563+
```
1564+
1565+
<br />

0 commit comments

Comments
 (0)