Skip to content

Commit

Permalink
feat: add useMemo & useCallback wrapper
Browse files Browse the repository at this point in the history
  • Loading branch information
afiiif committed Apr 24, 2024
1 parent 7c19496 commit d999794
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 22 deletions.
28 changes: 20 additions & 8 deletions snippets/javascript.json
Original file line number Diff line number Diff line change
Expand Up @@ -1226,14 +1226,6 @@
"description": "Testing `afterAll` / `afterEach` block",
"scope": "javascript,javascriptreact"
},
"🟨 wrapWithFunction": {
"prefix": "_func.$_func",
"body": [
"${1:func}($TM_SELECTED_TEXT)"
],
"description": "Wrap with function",
"scope": "javascript,javascriptreact"
},
"🟨 stringToTemplateLiterals": {
"prefix": "_lt.$_lt",
"body": [
Expand All @@ -1250,6 +1242,26 @@
"description": "Convert regular string in react prop's value to template literals",
"scope": "javascript,javascriptreact"
},
"🟨 wrapWithUseMemo": {
"prefix": "_useMemo.$_useMemo",
"body": [
"useMemo$0(() => {",
"\t$TM_SELECTED_TEXT",
"}, ${1:[]})"
],
"description": "Wrap with function",
"scope": "javascript,javascriptreact"
},
"🟨 wrapWithUseCallback": {
"prefix": "_useCallback.$_useCallback",
"body": [
"useCallback$0(",
"\t$TM_SELECTED_TEXT",
", ${1:[]})"
],
"description": "Wrap with function",
"scope": "javascript,javascriptreact"
},
"🟨 wrapWithFragment": {
"prefix": "_rFrag.$_rFrag._frag",
"body": [
Expand Down
28 changes: 20 additions & 8 deletions snippets/typescript.json
Original file line number Diff line number Diff line change
Expand Up @@ -1534,14 +1534,6 @@
"description": "Testing `afterAll` / `afterEach` block",
"scope": "javascript,typescript,javascriptreact,typescriptreact"
},
"🟨 wrapWithFunction": {
"prefix": "_func.$_func",
"body": [
"${1:func}($TM_SELECTED_TEXT)"
],
"description": "Wrap with function",
"scope": "javascript,typescript,javascriptreact,typescriptreact"
},
"🟨 stringToTemplateLiterals": {
"prefix": "_lt.$_lt",
"body": [
Expand All @@ -1558,6 +1550,26 @@
"description": "Convert regular string in react prop's value to template literals",
"scope": "javascript,typescript,javascriptreact,typescriptreact"
},
"🟨 wrapWithUseMemo": {
"prefix": "_useMemo.$_useMemo",
"body": [
"useMemo$0(() => {",
"\t$TM_SELECTED_TEXT",
"}, ${1:[]})"
],
"description": "Wrap with function",
"scope": "javascript,typescript,javascriptreact,typescriptreact"
},
"🟨 wrapWithUseCallback": {
"prefix": "_useCallback.$_useCallback",
"body": [
"useCallback$0(",
"\t$TM_SELECTED_TEXT",
", ${1:[]})"
],
"description": "Wrap with function",
"scope": "javascript,typescript,javascriptreact,typescriptreact"
},
"🟨 wrapWithFragment": {
"prefix": "_rFrag.$_rFrag._frag",
"body": [
Expand Down
18 changes: 12 additions & 6 deletions src/snippets/wrapper.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,5 @@
import { Snippet } from '../types';

export const wrapWithFunction: Snippet = {
prefix: '_func',
body: ['${1:func}($TM_SELECTED_TEXT)'],
description: 'Wrap with function',
};

export const stringToTemplateLiterals: Snippet = {
prefix: '_lt',
body: ['`${TM_SELECTED_TEXT/^[\'"](.*)[\'"]$/$1/g}`'],
Expand All @@ -18,6 +12,18 @@ export const reactStringPropToTemplateLiteral: Snippet = {
description: "Convert regular string in react prop's value to template literals",
};

export const wrapWithUseMemo: Snippet = {
prefix: '_useMemo',
body: ['useMemo$0(() => {', '\t$TM_SELECTED_TEXT', '}, ${1:[]})'],
description: 'Wrap with function',
};

export const wrapWithUseCallback: Snippet = {
prefix: '_useCallback',
body: ['useCallback$0(', '\t$TM_SELECTED_TEXT', ', ${1:[]})'],
description: 'Wrap with function',
};

export const wrapWithFragment: Snippet = {
prefix: ['_rFrag', '_frag'],
body: ['<$1$0>', '\t$TM_SELECTED_TEXT', '</$1>'],
Expand Down

0 comments on commit d999794

Please sign in to comment.