Skip to content

Commit

Permalink
docs: initQueryClient 설명 추가
Browse files Browse the repository at this point in the history
  • Loading branch information
scarf005 committed Jul 7, 2023
1 parent 082dd2d commit b473b47
Showing 1 changed file with 30 additions and 0 deletions.
30 changes: 30 additions & 0 deletions src/util/tsRestClient.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,36 @@
import { initQueryClient } from "@ts-rest/react-query";
import { contract } from "@jiphyeonjeon-42/contracts";

/**
* {@link https://tanstack.com/query/latest/docs/react/overview | @tanstack/react-query }의 쿼리들을
* {@link https://ts-rest.com/docs/react-query | ts-rest}로 타입 안전하게 감싼 객체입니다.
*
* API 요청 경로를 지정한 후
* react-query 라이브러리의 {@link https://tanstack.com/query/latest/docs/react/guides/queries | useQuery }및
* {@link https://tanstack.com/query/latest/docs/react/guides/mutations | useMutation }과 동일하게 사용 가능합니다.
*
* @example
* ```ts
* const mutation = client.reviews.patch.useMutation({
* onSuccess: ({ body }) => // ...
*
* onError: error => {
* switch (error.status) {
* case 401:
* return console.log(`에러코드: ${error.body.errorCode}`)
* case 404:
* return console.log(error.body.message)
* // message의 타입: "검색한 리뷰가 존재하지 않습니다."
* }
* },
* })
* ```
*
* @remarks 아래 링크를 참고하여 쿼리를 사용할 수 있습니다.
*
* @see https://tanstack.com/query/latest/docs/react/overview
* @see https://ts-rest.com/docs/react-query
*/
export const client = initQueryClient(contract, {
baseUrl: "http://localhost:3000",
baseHeaders: {},
Expand Down

0 comments on commit b473b47

Please sign in to comment.