Skip to content

Commit b24470f

Browse files
committed
feat: improve react custom hook snippet
1 parent 0597ef9 commit b24470f

File tree

3 files changed

+63
-9
lines changed

3 files changed

+63
-9
lines changed

snippets/javascript.json

+21-3
Original file line numberDiff line numberDiff line change
@@ -466,7 +466,7 @@
466466
"scope": "javascript,javascriptreact"
467467
},
468468
"🟨 reactCustomHook": {
469-
"prefix": "rfhook.$rfhook.hook",
469+
"prefix": "rFHook.$rFHook.hook",
470470
"body": [
471471
"import { useEffect } from 'react'",
472472
"",
@@ -484,7 +484,7 @@
484484
"scope": "javascript,javascriptreact"
485485
},
486486
"🟨 reactCustomHookArrowFn": {
487-
"prefix": "rafhook.$rafhook.hook",
487+
"prefix": "rAFHook.$rAFHook.hook",
488488
"body": [
489489
"import { useEffect } from 'react'",
490490
"",
@@ -500,7 +500,25 @@
500500
"",
501501
"export default $1"
502502
],
503-
"description": "React create custom hook",
503+
"description": "React create custom hook arrow function",
504+
"scope": "javascript,javascriptreact"
505+
},
506+
"🟨 reactCustomHookArrowFnExport": {
507+
"prefix": "rAFHookEx.$rAFHookEx.hook",
508+
"body": [
509+
"import { useEffect } from 'react'",
510+
"",
511+
"export const ${1:${RELATIVE_FILEPATH/(^.+?(?=[\\/\\\\][^\\/\\\\]+[\\/\\\\][^\\/\\\\]+\\.[jt]sx?))|(\\.[jt]sx?$|[\\/\\\\](?:index|\\[).*|.+[\\/\\\\](?!(?:index|\\[))|[.\\-_\\/\\\\])|([\\w\\-_]*)/${3:/camelcase}/g}} = () => {",
512+
"\t${0:// code}",
513+
"\t",
514+
"\tuseEffect(() => {",
515+
"\t\t// code",
516+
"\t}, [])",
517+
"\t",
518+
"\treturn null",
519+
"}"
520+
],
521+
"description": "React create custom hook arrow function",
504522
"scope": "javascript,javascriptreact"
505523
},
506524
"🟨 nextSSR": {

snippets/typescript.json

+21-3
Original file line numberDiff line numberDiff line change
@@ -610,7 +610,7 @@
610610
"scope": "javascript,typescript,javascriptreact,typescriptreact"
611611
},
612612
"🟨 reactCustomHook": {
613-
"prefix": "rfhook.$rfhook.hook",
613+
"prefix": "rFHook.$rFHook.hook",
614614
"body": [
615615
"import { useEffect } from 'react'",
616616
"",
@@ -628,7 +628,7 @@
628628
"scope": "javascript,typescript,javascriptreact,typescriptreact"
629629
},
630630
"🟨 reactCustomHookArrowFn": {
631-
"prefix": "rafhook.$rafhook.hook",
631+
"prefix": "rAFHook.$rAFHook.hook",
632632
"body": [
633633
"import { useEffect } from 'react'",
634634
"",
@@ -644,7 +644,25 @@
644644
"",
645645
"export default $1"
646646
],
647-
"description": "React create custom hook",
647+
"description": "React create custom hook arrow function",
648+
"scope": "javascript,typescript,javascriptreact,typescriptreact"
649+
},
650+
"🟨 reactCustomHookArrowFnExport": {
651+
"prefix": "rAFHookEx.$rAFHookEx.hook",
652+
"body": [
653+
"import { useEffect } from 'react'",
654+
"",
655+
"export const ${1:${RELATIVE_FILEPATH/(^.+?(?=[\\/\\\\][^\\/\\\\]+[\\/\\\\][^\\/\\\\]+\\.[jt]sx?))|(\\.[jt]sx?$|[\\/\\\\](?:index|\\[).*|.+[\\/\\\\](?!(?:index|\\[))|[.\\-_\\/\\\\])|([\\w\\-_]*)/${3:/camelcase}/g}} = () => {",
656+
"\t${0:// code}",
657+
"\t",
658+
"\tuseEffect(() => {",
659+
"\t\t// code",
660+
"\t}, [])",
661+
"\t",
662+
"\treturn null",
663+
"}"
664+
],
665+
"description": "React create custom hook arrow function",
648666
"scope": "javascript,typescript,javascriptreact,typescriptreact"
649667
},
650668
"🟦 TS UseState": {

src/snippets/react-hook.ts

+21-3
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ export const useCallback: Snippet = {
7474
};
7575

7676
export const reactCustomHook: Snippet = {
77-
prefix: ['rfhook', 'hook'],
77+
prefix: ['rFHook', 'hook'],
7878
body: [
7979
"import { useEffect } from 'react'",
8080
'',
@@ -92,7 +92,7 @@ export const reactCustomHook: Snippet = {
9292
};
9393

9494
export const reactCustomHookArrowFn: Snippet = {
95-
prefix: ['rafhook', 'hook'],
95+
prefix: ['rAFHook', 'hook'],
9696
body: [
9797
"import { useEffect } from 'react'",
9898
'',
@@ -108,5 +108,23 @@ export const reactCustomHookArrowFn: Snippet = {
108108
'',
109109
'export default $1',
110110
],
111-
description: 'React create custom hook',
111+
description: 'React create custom hook arrow function',
112+
};
113+
114+
export const reactCustomHookArrowFnExport: Snippet = {
115+
prefix: ['rAFHookEx', 'hook'],
116+
body: [
117+
"import { useEffect } from 'react'",
118+
'',
119+
`export const \${1:${FILENAME_CAMELCASE}} = () => {`,
120+
'\t${0:// code}',
121+
'\t',
122+
'\tuseEffect(() => {',
123+
'\t\t// code',
124+
'\t}, [])',
125+
'\t',
126+
'\treturn null',
127+
'}',
128+
],
129+
description: 'React create custom hook arrow function',
112130
};

0 commit comments

Comments
 (0)