Skip to content

Commit 4237273

Browse files
committed
chore: update snippets
1 parent f92e2be commit 4237273

File tree

2 files changed

+49
-14
lines changed

2 files changed

+49
-14
lines changed

.vscode/project.code-snippets

Lines changed: 47 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@
4343
],
4444
"description": "Component"
4545
},
46-
// https://snippet-generator.app/?description=useQuery+with+variables&tabtrigger=useqv&snippet=import+type+%7B+AxiosError+%7D+from+%27axios%27%3B%0Aimport+%7B+createQuery+%7D+from+%27react-query-kit%27%3B%0A%0Aimport+%7B+client+%7D+from+%27..%2Fcommon%27%3B%0A%0Atype+Variables+%3D+%7B%243%7D%3B%0Atype+Response+%3D%7B%244%7D%3B%0A%0Aexport+const+use%241+%3D+createQuery%3CResponse%2C+Variables%2C+AxiosError%3E%28%7B%0A++primaryKey%3A+%27%242%27%2C%0A++queryFn%3A+%28%7B+queryKey%3A+%5BprimaryKey%2C+variables%5D+%7D%29+%3D%3E+%7B%0A++++return+client%0A++++++.get%28%60%5C%24%7BprimaryKey%7D%2F%5C%24%7Bvariables.%24%7B5%7D%7D%60%29%0A++++++.then%28%28response%29+%3D%3E+response.data%29%3B%0A++%7D%2C%0A%7D%29%3B&mode=vscode
46+
// https://snippet-generator.app/?description=useQuery+with+variables&tabtrigger=useqv&snippet=import+type+%7B+AxiosError+%7D+from+%27axios%27%3B%0Aimport+%7B+createQuery+%7D+from+%27react-query-kit%27%3B%0A%0Aimport+%7B+client+%7D+from+%27..%2Fcommon%27%3B%0A%0Atype+Variables+%3D+%7B%243%7D%3B%0Atype+Response+%3D+%7B%244%7D%3B%0A%0Aexport+const+use%241+%3D+createQuery%3CResponse%2C+Variables%2C+AxiosError%3E%28%7B%0A++queryKey%3A+%5B%27%242%27%5D%2C+%0A++fetcher%3A+%28variables%29+%3D%3E+%7B%0A++++return+client%0A++++++.get%28%60%242%2F%5C%5C%24%7Bvariables.%24%7B5%7D%7D%60%29%22%2C%0A++++++.then%28%28response%29+%3D%3E+response.data%29%3B%0A++%7D%2C%0A%7D%29%3B%0A&mode=vscode
4747
"useQuery with variables": {
4848
"prefix": "useqv",
4949
"body": [
@@ -53,20 +53,21 @@
5353
"import { client } from '../common';",
5454
"",
5555
"type Variables = {$3};",
56-
"type Response ={$4};",
56+
"type Response = {$4};",
5757
"",
5858
"export const use$1 = createQuery<Response, Variables, AxiosError>({",
59-
" primaryKey: '$2',",
60-
" queryFn: ({ queryKey: [primaryKey, variables] }) => {",
59+
" queryKey: ['$2'], ",
60+
" fetcher: (variables) => {",
6161
" return client",
62-
" .get(`\\${primaryKey}/\\${variables.${5}}`)",
62+
" .get(`$2/\\${variables.${5}}`)",
6363
" .then((response) => response.data);",
6464
" },",
65-
"});"
65+
"});",
66+
""
6667
],
6768
"description": "useQuery with variables"
6869
},
69-
//https://snippet-generator.app/?description=useQuery&tabtrigger=useq&snippet=import+type+%7B+AxiosError+%7D+from+%27axios%27%3B%0Aimport+%7B+createQuery+%7D+from+%27react-query-kit%27%3B%0A%0Aimport+%7B+client+%7D+from+%27..%2Fcommon%27%3B%0A%0Atype+Response+%3D+%7B%243%7D%3B%0Atype+Variables+%3D+void%3B%0A%0Aexport+const+use%241+%3D+createQuery%3CResponse%2C+Variables%2C+AxiosError%3E%28%7B%0A++primaryKey%3A+%60%242%60%2C%0A++queryFn%3A+%28%7B+queryKey%3A+%5BprimaryKey%5D+%7D%29+%3D%3E+%7B%0A++++return+client.get%28%60%5C%24%7BprimaryKey%7D%60%29.then%28%28response%29+%3D%3E+response.data.posts%29%3B%0A++%7D%0A%7D%29%3B&mode=vscode
70+
//https://snippet-generator.app/?description=useQuery&tabtrigger=useq&snippet=import+type+%7B+AxiosError+%7D+from+%27axios%27%3B%0Aimport+%7B+createQuery+%7D+from+%27react-query-kit%27%3B%0A%0Aimport+%7B+client+%7D+from+%27..%2Fcommon%27%3B%0A%0Atype+Response+%3D+%7B%243%7D%3B%0Atype+Variables+%3D+void%3B%0A%0Aexport+const+use%241+%3D+createQuery%3CResponse%2C+Variables%2C+AxiosError%3E%28%7B%0A++queryKey%3A+%5B%27%242%27%5D%2C%0A++fetcher%3A+%28%29+%3D%3E+%7B%0A++++return+client.get%28%60%242%60%29.then%28%28response%29+%3D%3E+response.data.posts%29%3B%0A++%7D%2C%0A%7D%29%3B%0A&mode=vscode
7071
"useQuery": {
7172
"prefix": "useq",
7273
"body": [
@@ -79,14 +80,48 @@
7980
"type Variables = void;",
8081
"",
8182
"export const use$1 = createQuery<Response, Variables, AxiosError>({",
82-
" primaryKey: `$2`,",
83-
" queryFn: ({ queryKey: [primaryKey] }) => {",
84-
" return client.get(`\\${primaryKey}`).then((response) => response.data.posts);",
85-
" }",
86-
"});"
83+
" queryKey: ['$2'],",
84+
" fetcher: () => {",
85+
" return client.get(`$2`).then((response) => response.data.posts);",
86+
" },",
87+
"});",
88+
""
8789
],
8890
"description": "useQuery"
8991
},
92+
//https://snippet-generator.app/?description=useInfiniteQuery&tabtrigger=useiq&snippet=import+type+%7B+AxiosError+%7D+from+%27axios%27%3B%0Aimport+%7B+createInfiniteQuery+%7D+from+%27react-query-kit%27%3B%0A%0Aimport+%7B+client+%7D+from+%27..%2Fcommon%2Fclient%27%3B%0Aimport+%7B+DEFAULT_LIMIT%2C+getNextPageParam+%7D+from+%27..%2Fcommon%2Futils%27%3B%0Aimport+type+%7B+PaginateQuery+%7D+from+%27..%2Ftypes%27%3B%0A%0Atype+Response+%3D+void%3B%0Atype+Variables+%3D+PaginateQuery%3C%243%3E%3B%0A%0Aexport+const+use%241+%3D+createInfiniteQuery%3CResponse%2C+Variables%2C+AxiosError%3E%28%7B%0A++queryKey%3A+%5B%27%242%27%5D%2C%0A++fetcher%3A+%28_variables%3A+any%2C+%7B+pageParam+%7D%29%3A+Promise%3CResponse%3E+%3D%3E+%7B%0A++++return+client%28%7B%0A++++++url%3A+%60%2F%242%2F%60%2C%0A++++++method%3A+%27GET%27%2C%0A++++++params%3A+%7B%0A++++++++limit%3A+DEFAULT_LIMIT%2C%0A++++++++offset%3A+pageParam%2C%0A++++++%7D%2C%0A++++%7D%29.then%28%28response%29+%3D%3E+response.data%29%3B%0A++%7D%2C%0A++getNextPageParam%2C%0A++initialPageParam%3A+0%2C%0A%7D%29%3B&mode=vscode
93+
"useInfiniteQuery": {
94+
"prefix": "useiq",
95+
"body": [
96+
"import type { AxiosError } from 'axios';",
97+
"import { createInfiniteQuery } from 'react-query-kit';",
98+
"",
99+
"import { client } from '../common/client';",
100+
"import { DEFAULT_LIMIT, getNextPageParam } from '../common/utils';",
101+
"import type { PaginateQuery } from '../types';",
102+
"",
103+
"type Response = void;",
104+
"type Variables = PaginateQuery<$3>;",
105+
"",
106+
"export const use$1 = createInfiniteQuery<Response, Variables, AxiosError>({",
107+
" queryKey: ['$2'],",
108+
" fetcher: (_variables: any, { pageParam }): Promise<Response> => {",
109+
" return client({",
110+
" url: `/$2/`,",
111+
" method: 'GET',",
112+
" params: {",
113+
" limit: DEFAULT_LIMIT,",
114+
" offset: pageParam,",
115+
" },",
116+
" }).then((response) => response.data);",
117+
" },",
118+
" getNextPageParam,",
119+
" initialPageParam: 0,",
120+
"});"
121+
],
122+
"description": "useInfiniteQuery"
123+
},
124+
90125
//https://snippet-generator.app/?description=useMutation+&tabtrigger=usem&snippet=import+type+%7B+AxiosError+%7D+from+%27axios%27%3B%0Aimport+%7B+createMutation+%7D+from+%27react-query-kit%27%3B%0A%0Aimport+%7B+client+%7D+from+%27..%2Fcommon%27%3B%0A%0Atype+Variables+%3D+%7B%243%7D%3B%0Atype+Response+%3D+%7B%244%7D%3B%0A%0Aexport+const+use%241+%3D+createMutation%3CResponse%2C+Variables%2C+AxiosError%3E%28%0A++async+%28variables%29+%3D%3E%0A++++client%28%7B%0A++++++url%3A+%27%242%27%2C%0A++++++method%3A+%27POST%27%2C%0A++++++data%3A+variables%2C%0A++++%7D%29.then%28%28response%29+%3D%3E+response.data%29%0A%29%3B&mode=vscode
91126
"useMutation ": {
92127
"prefix": "usem",

src/api/types.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
export interface PaginateQuery<T> {
1+
export type PaginateQuery<T> = {
22
results: T[];
33
count: number;
44
next: string | null;
55
previous: string | null;
6-
}
6+
};

0 commit comments

Comments
 (0)