-
Notifications
You must be signed in to change notification settings - Fork 1
/
snippets.json
172 lines (172 loc) · 4.78 KB
/
snippets.json
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
{
"Endpoint Function": {
"prefix": "rendpoint",
"body": [
"export const $1 = safeEndPoint(async (req: NextRequest, route: { params: { id: string } }) => {",
" try {",
" const body = $2.parse(await getBodyAsync(req));",
" const params = $2.parse(getParams(req));",
" const uriParams = route.params;",
"",
" return NextResponse.json({});",
" } catch (err) {",
" return errorResponse(err as Error);",
" }",
"}, false);"
],
"description": "Endpoint Function"
},
"React Form Component": {
"prefix": "rformtag",
"body": [
"<Form {...form}>",
" <form onSubmit={form.handleSubmit(onSubmit)}>"
],
"description": "React Form Component"
},
"React onSubmit Function": {
"prefix": "rsubmit",
"body": [
"async function onSubmit(values: Form) {",
" $2",
"}"
],
"description": "React onSubmit Function"
},
"React useForm": {
"prefix": "rform",
"body": [
"const $1 = z.object({",
"",
"});",
"",
"type Form = z.infer<typeof $1>;",
"",
"const form = useForm<Form>({",
" resolver: zodResolver($1),",
" defaultValues: {",
" $2",
" },",
"});"
],
"description": "React useForm with zodResolver"
},
"React FormField": {
"prefix": "rfield",
"body": [
"<div>",
" <FormField",
" control={form.control}",
" name=\"$1\"",
" render={({ field }) => (",
" <FormItem>",
" <FormLabel>$2</FormLabel>",
" <FormControl>",
" <Input",
" placeholder=\"$3\"",
" {...field}",
" />",
" </FormControl>",
" <FormMessage className=\"text-xs\" />",
" </FormItem>",
" )}",
" />",
"</div>"
],
"description": "React FormField Password Component"
},
"resp": {
"prefix": "resp",
"body": [
"return NextResponse.json({",
" error : false,",
" message : \"$1\"",
" $2",
"});",
"}"
],
"description": "Returns an invalid input response."
},
"rrouter": {
"prefix": "rrouter",
"body": [
"const router = useRouter()"
]
},
"reactConst": {
"prefix": "rconst",
"body": [
"const $1 = () => {",
" return $2",
"}"
]
},
"reactFun": {
"prefix": "rfun",
"body": [
"function $1() {",
"return $2",
"}"
]
},
"React UseMutation": {
"prefix": "rmutation",
"body": [
"const { mutate: $1, isLoading } = useMutation(async () =>",
" api.post<Resp<$2>>(\"/api/$3\")",
");"
],
"description": "React UseMutation snippet"
},
"React Query - useQuery Hook": {
"prefix": "rquery",
"body": [
"const { data, isLoading, isError, error } = useQuery(['$1'], async () => $2 ",
"});"
],
"description": "React Query - useQuery Hook snippet"
},
"React useEffect Hook": {
"prefix": "ruseffect",
"body": [
"useEffect(function $1() {",
"$2",
"}, []);"
],
"description": "React useEffect Hook"
},
"log": {
"prefix": "ll",
"body": [
"console.log('***',$1)"
]
},
"React State with useState": {
"prefix": "rstate",
"body": [
"import { useState } from 'react'",
"const [${1:stateName}, ${1/(.)(.*)/${1:/downcase}${2:/capitalize}/}] = useState(${2:initialValue});"
],
"description": "Create a React state using the useState hook."
},
"React Componcnt with Typescript Props Interface": {
"prefix": "rComp",
"body": [
"export function $1 (p: { $2 }) {",
" return (",
" <>",
" </>",
" );",
"}"
],
"description": "Create a React component with Typescript props interface."
},
"Next Page with Typescript Props Interface": {
"prefix": "rpage",
"body": [
"export default function $1(p: {}) {",
" return <></>;",
"}"
]
}
}