|
43 | 43 | ], |
44 | 44 | "description": "Component" |
45 | 45 | }, |
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 |
47 | 47 | "useQuery with variables": { |
48 | 48 | "prefix": "useqv", |
49 | 49 | "body": [ |
|
53 | 53 | "import { client } from '../common';", |
54 | 54 | "", |
55 | 55 | "type Variables = {$3};", |
56 | | - "type Response ={$4};", |
| 56 | + "type Response = {$4};", |
57 | 57 | "", |
58 | 58 | "export const use$1 = createQuery<Response, Variables, AxiosError>({", |
59 | | - " primaryKey: '$2',", |
60 | | - " queryFn: ({ queryKey: [primaryKey, variables] }) => {", |
| 59 | + " queryKey: ['$2'], ", |
| 60 | + " fetcher: (variables) => {", |
61 | 61 | " return client", |
62 | | - " .get(`\\${primaryKey}/\\${variables.${5}}`)", |
| 62 | + " .get(`$2/\\${variables.${5}}`)", |
63 | 63 | " .then((response) => response.data);", |
64 | 64 | " },", |
65 | | - "});" |
| 65 | + "});", |
| 66 | + "" |
66 | 67 | ], |
67 | 68 | "description": "useQuery with variables" |
68 | 69 | }, |
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 |
70 | 71 | "useQuery": { |
71 | 72 | "prefix": "useq", |
72 | 73 | "body": [ |
|
79 | 80 | "type Variables = void;", |
80 | 81 | "", |
81 | 82 | "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 | + "" |
87 | 89 | ], |
88 | 90 | "description": "useQuery" |
89 | 91 | }, |
| 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 | + |
90 | 125 | //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 |
91 | 126 | "useMutation ": { |
92 | 127 | "prefix": "usem", |
|
0 commit comments