Skip to content

Commit b89d233

Browse files
committed
feat: add useMemo & useCallback wrapper
1 parent 6c18b37 commit b89d233

File tree

3 files changed

+52
-22
lines changed

3 files changed

+52
-22
lines changed

snippets/javascript.json

+20-8
Original file line numberDiff line numberDiff line change
@@ -1226,14 +1226,6 @@
12261226
"description": "Testing `afterAll` / `afterEach` block",
12271227
"scope": "javascript,javascriptreact"
12281228
},
1229-
"🟨 wrapWithFunction": {
1230-
"prefix": "_func.$_func",
1231-
"body": [
1232-
"${1:func}($TM_SELECTED_TEXT)"
1233-
],
1234-
"description": "Wrap with function",
1235-
"scope": "javascript,javascriptreact"
1236-
},
12371229
"🟨 stringToTemplateLiterals": {
12381230
"prefix": "_lt.$_lt",
12391231
"body": [
@@ -1250,6 +1242,26 @@
12501242
"description": "Convert regular string in react prop's value to template literals",
12511243
"scope": "javascript,javascriptreact"
12521244
},
1245+
"🟨 wrapWithUseMemo": {
1246+
"prefix": "_useMemo.$_useMemo",
1247+
"body": [
1248+
"useMemo$0(() => {",
1249+
"\t$TM_SELECTED_TEXT",
1250+
"}, ${1:[]})"
1251+
],
1252+
"description": "Wrap with function",
1253+
"scope": "javascript,javascriptreact"
1254+
},
1255+
"🟨 wrapWithUseCallback": {
1256+
"prefix": "_useCallback.$_useCallback",
1257+
"body": [
1258+
"useCallback$0(",
1259+
"\t$TM_SELECTED_TEXT",
1260+
", ${1:[]})"
1261+
],
1262+
"description": "Wrap with function",
1263+
"scope": "javascript,javascriptreact"
1264+
},
12531265
"🟨 wrapWithFragment": {
12541266
"prefix": "_rFrag.$_rFrag._frag",
12551267
"body": [

snippets/typescript.json

+20-8
Original file line numberDiff line numberDiff line change
@@ -1534,14 +1534,6 @@
15341534
"description": "Testing `afterAll` / `afterEach` block",
15351535
"scope": "javascript,typescript,javascriptreact,typescriptreact"
15361536
},
1537-
"🟨 wrapWithFunction": {
1538-
"prefix": "_func.$_func",
1539-
"body": [
1540-
"${1:func}($TM_SELECTED_TEXT)"
1541-
],
1542-
"description": "Wrap with function",
1543-
"scope": "javascript,typescript,javascriptreact,typescriptreact"
1544-
},
15451537
"🟨 stringToTemplateLiterals": {
15461538
"prefix": "_lt.$_lt",
15471539
"body": [
@@ -1558,6 +1550,26 @@
15581550
"description": "Convert regular string in react prop's value to template literals",
15591551
"scope": "javascript,typescript,javascriptreact,typescriptreact"
15601552
},
1553+
"🟨 wrapWithUseMemo": {
1554+
"prefix": "_useMemo.$_useMemo",
1555+
"body": [
1556+
"useMemo$0(() => {",
1557+
"\t$TM_SELECTED_TEXT",
1558+
"}, ${1:[]})"
1559+
],
1560+
"description": "Wrap with function",
1561+
"scope": "javascript,typescript,javascriptreact,typescriptreact"
1562+
},
1563+
"🟨 wrapWithUseCallback": {
1564+
"prefix": "_useCallback.$_useCallback",
1565+
"body": [
1566+
"useCallback$0(",
1567+
"\t$TM_SELECTED_TEXT",
1568+
", ${1:[]})"
1569+
],
1570+
"description": "Wrap with function",
1571+
"scope": "javascript,typescript,javascriptreact,typescriptreact"
1572+
},
15611573
"🟨 wrapWithFragment": {
15621574
"prefix": "_rFrag.$_rFrag._frag",
15631575
"body": [

src/snippets/wrapper.ts

+12-6
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,5 @@
11
import { Snippet } from '../types';
22

3-
export const wrapWithFunction: Snippet = {
4-
prefix: '_func',
5-
body: ['${1:func}($TM_SELECTED_TEXT)'],
6-
description: 'Wrap with function',
7-
};
8-
93
export const stringToTemplateLiterals: Snippet = {
104
prefix: '_lt',
115
body: ['`${TM_SELECTED_TEXT/^[\'"](.*)[\'"]$/$1/g}`'],
@@ -18,6 +12,18 @@ export const reactStringPropToTemplateLiteral: Snippet = {
1812
description: "Convert regular string in react prop's value to template literals",
1913
};
2014

15+
export const wrapWithUseMemo: Snippet = {
16+
prefix: '_useMemo',
17+
body: ['useMemo$0(() => {', '\t$TM_SELECTED_TEXT', '}, ${1:[]})'],
18+
description: 'Wrap with function',
19+
};
20+
21+
export const wrapWithUseCallback: Snippet = {
22+
prefix: '_useCallback',
23+
body: ['useCallback$0(', '\t$TM_SELECTED_TEXT', ', ${1:[]})'],
24+
description: 'Wrap with function',
25+
};
26+
2127
export const wrapWithFragment: Snippet = {
2228
prefix: ['_rFrag', '_frag'],
2329
body: ['<$1$0>', '\t$TM_SELECTED_TEXT', '</$1>'],

0 commit comments

Comments
 (0)