@uiwwsw/react-query-helper 0.1.0 → 0.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/README.md +11 -16
  2. package/package.json +1 -1
package/README.md CHANGED
@@ -1,4 +1,3 @@
1
-
2
1
  # React Query Helper
3
2
 
4
3
  ![React Query Helper Logo](https://raw.githubusercontent.com/uiwwsw/react-query-helper/main/assets/logo.png) <!-- 로고 이미지가 있다면 여기에 추가하세요. 없으면 이 줄을 삭제하거나 주석 처리하세요. -->
@@ -38,6 +37,7 @@ const config = {
38
37
  sourceDir: "./libs", // API 함수가 정의된 TypeScript 파일들이 있는 디렉토리 (예: libs/users/api.ts)
39
38
  outputDir: "./src/options", // React Query 훅 및 옵션 파일이 생성될 디렉토리
40
39
  // ignoredFiles: ["some-ignored-file.ts"], // (선택 사항) 코드 생성에서 제외할 파일 이름들의 배열
40
+ // templateDir: "./custom-templates", // (선택 사항) 사용자 정의 템플릿 디렉토리
41
41
  };
42
42
 
43
43
  export default config;
@@ -92,33 +92,28 @@ export function deleteUser(id: string) {
92
92
  // src/options/users/apiOptions.ts (예시 - 경로는 rqh.config.ts 설정에 따라 달라짐)
93
93
  import { getUser, createUser, deleteUser } from "../../../libs/users/api"; // API 파일 경로도 상대적으로 참조됩니다.
94
94
  import { useQuery, useMutation } from "@tanstack/react-query";
95
+ import { queryOption, mutationOption } from "@uiwwsw/react-query-helper/utils/query"; // @src/utils/query.ts에서 가져온 유틸리티 함수
95
96
 
96
97
  // getUser에 대한 React Query 훅
97
98
  export const useGetUserQuery = (id: string, options?: any) => {
98
- return useQuery({
99
- queryKey: ["users", id],
100
- queryFn: () => getUser(id),
101
- ...options,
102
- });
99
+ return useQuery(queryOption(["users", id], () => getUser(id))(id));
103
100
  };
104
101
 
105
102
  // createUser에 대한 React Query 뮤테이션 훅
106
103
  export const useCreateUserMutation = (options?: any) => {
107
- return useMutation({
108
- mutationFn: (name: string) => createUser(name),
109
- ...options,
110
- });
104
+ return useMutation(mutationOption(["users"], createUser)());
111
105
  };
112
106
 
113
107
  // deleteUser에 대한 React Query 뮤테이션 훅
114
108
  export const useDeleteUserMutation = (options?: any) => {
115
- return useMutation({
116
- mutationFn: (id: string) => deleteUser(id),
117
- ...options,
118
- });
109
+ return useMutation(mutationOption(["users"], deleteUser)());
119
110
  };
120
111
  ```
121
112
 
113
+ **`@uiwwsw/react-query-helper/utils/query.ts`의 강력함:**
114
+
115
+ 위 예시에서 볼 수 있듯이, `queryOption`, `mutationOption`, `infiniteOption`과 같은 유틸리티 함수들을 활용하여 React Query 훅의 기본 설정을 중앙에서 관리하고 재사용할 수 있습니다. 예를 들어, 모든 쿼리에 `staleTime: Infinity`나 `refetchOnWindowFocus: false`와 같은 공통 옵션을 적용하고 싶다면, `src/utils/query.ts` 파일 내의 해당 유틸리티 함수를 수정하는 것만으로 모든 생성된 훅에 반영됩니다. 이는 일관된 캐싱 전략, 에러 처리, 재시도 로직 등을 쉽게 적용할 수 있게 하여 개발 효율성을 크게 높여줍니다.
116
+
122
117
  이제 애플리케이션에서 이 훅들을 가져와 사용할 수 있습니다. **가져오는 경로 또한 `rqh.config.ts`의 `outputDir` 설정에 따라 달라집니다.**
123
118
 
124
119
  ```typescript
@@ -154,7 +149,7 @@ function UserProfile({ userId }: { userId: string }) {
154
149
  - `sourceDir`: (필수) API 함수가 정의된 TypeScript 파일들이 있는 디렉토리의 경로입니다. 이 디렉토리 내의 `.ts` 파일들을 분석하여 React Query 코드를 생성합니다. 프로젝트 루트를 기준으로 한 상대 경로를 사용합니다.
155
150
  - `outputDir`: (필수) 생성된 React Query 훅 및 옵션 파일이 저장될 디렉토리의 경로입니다. 프로젝트 루트를 기준으로 한 상대 경로를 사용합니다.
156
151
  - `ignoredFiles`: (선택 사항) 코드 생성 과정에서 무시할 파일 이름들의 배열입니다. (예: `["utils.ts", "types.ts"]`) 이 목록에 있는 파일은 `sourceDir` 내에 있더라도 코드가 생성되지 않습니다.
157
- - `templateDir`: (선택 사항) 내부적으로 사용되는 템플릿 디렉토리입니다. 일반적으로 사용자가 직접 설정할 필요는 없습니다.
152
+ - `templateDir`: (선택 사항) `React Query Helper`가 훅을 생성할 때 사용할 사용자 정의 템플릿 파일들이 있는 디렉토리의 경로입니다. 이 옵션을 설정하면 기본 템플릿 대신 지정된 템플릿을 사용하여 훅을 생성할 수 있습니다. 이를 통해 `queryOption`, `mutationOption` 등과 같은 사용자 정의 유틸리티 함수를 활용하여 생성되는 훅의 동작을 세밀하게 제어할 수 있습니다. 프로젝트 루트를 기준으로 한 상대 경로를 사용합니다. (예: `templateDir: "./custom-templates"`)
158
153
 
159
154
  ## 🤝 기여
160
155
 
@@ -162,4 +157,4 @@ function UserProfile({ userId }: { userId: string }) {
162
157
 
163
158
  ## 📄 라이선스
164
159
 
165
- 이 프로젝트는 [LICENSE](LICENSE) 파일에 명시된 라이선스에 따라 배포됩니다.
160
+ 이 프로젝트는 [LICENSE](LICENSE) 파일에 명시된 라이선스에 따라 배포됩니다.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@uiwwsw/react-query-helper",
3
- "version": "0.1.0",
3
+ "version": "0.1.1",
4
4
  "module": "dist/index.js",
5
5
  "type": "module",
6
6
  "types": "dist/index.d.ts",