From 1d52d3273a5cc5a21c8818fc622335c94bc221ce Mon Sep 17 00:00:00 2001 From: Muhammad Afifudin Date: Wed, 22 Feb 2023 06:04:11 +0700 Subject: [PATCH] feat: update useMemo & useCallback snippet --- snippets/javascript.json | 6 ++---- snippets/typescript.json | 12 ++++-------- src/snippets/react-hook-ts.ts | 8 ++++++-- src/snippets/react-hook.ts | 4 ++-- 4 files changed, 14 insertions(+), 16 deletions(-) diff --git a/snippets/javascript.json b/snippets/javascript.json index 04741c6..009ffba 100644 --- a/snippets/javascript.json +++ b/snippets/javascript.json @@ -450,8 +450,7 @@ "🟨 useMemo": { "prefix": "useMemo.$useMemo", "body": [ - "const ${1:memo} = useMemo$4(() => ${3:computeValue}, [$2])", - "" + "const ${1:memo} = useMemo$4(() => ${3:computeValue}, [$2])" ], "description": "React useMemo", "scope": "javascript,javascriptreact" @@ -461,8 +460,7 @@ "body": [ "const ${1:callback} = useCallback$4(() => {", "\t${3:// code}", - "}, [$2])", - "" + "}, [$2])" ], "description": "React useCallback", "scope": "javascript,javascriptreact" diff --git a/snippets/typescript.json b/snippets/typescript.json index 791fa1d..f45090f 100644 --- a/snippets/typescript.json +++ b/snippets/typescript.json @@ -594,8 +594,7 @@ "🟨 useMemo": { "prefix": "useMemo.$useMemo", "body": [ - "const ${1:memo} = useMemo$4(() => ${3:computeValue}, [$2])", - "" + "const ${1:memo} = useMemo$4(() => ${3:computeValue}, [$2])" ], "description": "React useMemo", "scope": "javascript,typescript,javascriptreact,typescriptreact" @@ -605,8 +604,7 @@ "body": [ "const ${1:callback} = useCallback$4(() => {", "\t${3:// code}", - "}, [$2])", - "" + "}, [$2])" ], "description": "React useCallback", "scope": "javascript,typescript,javascriptreact,typescriptreact" @@ -668,8 +666,7 @@ "🟦 TS UseMemo": { "prefix": "useMemo.TS.$$useMemo", "body": [ - "const ${1:memo} = useMemo$5<${4:any}>(() => ${3:computeValue}, [$2])", - "" + "const ${1:memo} = useMemo$5<${4:any}>(() => ${3:computeValue}, [$2])" ], "description": "React useMemo", "scope": "javascript,typescript,javascriptreact,typescriptreact" @@ -679,8 +676,7 @@ "body": [ "const ${1:callback} = useCallback$5<() => ${4:void}>(() => {", "\t${3:// code}", - "}, [$2])", - "" + "}, [$2])" ], "description": "React useCallback", "scope": "javascript,typescript,javascriptreact,typescriptreact" diff --git a/src/snippets/react-hook-ts.ts b/src/snippets/react-hook-ts.ts index c10c1d9..5e59dc4 100644 --- a/src/snippets/react-hook-ts.ts +++ b/src/snippets/react-hook-ts.ts @@ -14,12 +14,16 @@ export const tsUseRef: Snippet = { export const tsUseMemo: Snippet = { prefix: 'useMemo', - body: ['useMemo$4<${3:any}>(() => ${2:computeValue}, [$1])'], + body: ['const ${1:memo} = useMemo$5<${4:any}>(() => ${3:computeValue}, [$2])'], description: 'React useMemo', }; export const tsUseCallback: Snippet = { prefix: 'useCallback', - body: ['useCallback$4<() => ${3:void}>(() => {', '\t${2:// code}', '}, [$1])', ''], + body: [ + 'const ${1:callback} = useCallback$5<() => ${4:void}>(() => {', + '\t${3:// code}', + '}, [$2])', + ], description: 'React useCallback', }; diff --git a/src/snippets/react-hook.ts b/src/snippets/react-hook.ts index c5d2846..4c7d365 100644 --- a/src/snippets/react-hook.ts +++ b/src/snippets/react-hook.ts @@ -63,13 +63,13 @@ export const useLayoutEffectV2: Snippet = { export const useMemo: Snippet = { prefix: 'useMemo', - body: ['useMemo$3(() => ${2:computeValue}, [$1])'], + body: ['const ${1:memo} = useMemo$4(() => ${3:computeValue}, [$2])'], description: 'React useMemo', }; export const useCallback: Snippet = { prefix: 'useCallback', - body: ['useCallback$3(() => {', '\t${2:// code}', '}, [$1])', ''], + body: ['const ${1:callback} = useCallback$4(() => {', '\t${3:// code}', '}, [$2])'], description: 'React useCallback', };