Skip to content

Commit e7b4f14

Browse files
committed
feat(react): add hoc snippet
1 parent 37ec2f4 commit e7b4f14

File tree

3 files changed

+45
-2
lines changed

3 files changed

+45
-2
lines changed

snippets/javascript.json

+15
Original file line numberDiff line numberDiff line change
@@ -297,6 +297,21 @@
297297
"description": "React Arrow Function Component with PropTypes",
298298
"scope": "javascript,javascriptreact"
299299
},
300+
"hocComponent": {
301+
"prefix": "hoc.$hoc.🟨",
302+
"body": [
303+
"export default function ${1:${RELATIVE_FILEPATH/(^.+?(?=[\\/\\\\][^\\/\\\\]+[\\/\\\\][^\\/\\\\]+\\.[jt]sx?))|(\\.[jt]sx?$|[\\/\\\\](?:index|\\[).*|.+[\\/\\\\](?!(?:index|\\[))|[.\\-_\\/\\\\])|([\\w\\-_]*)/${3:/camelcase}/g}}(WrappedComponent) {$0",
304+
"\tconst Component = (props) => {",
305+
"\t\treturn <WrappedComponent {...props} />",
306+
"\t}",
307+
"",
308+
"\treturn Component",
309+
"}",
310+
""
311+
],
312+
"description": "React HOC",
313+
"scope": "javascript,javascriptreact"
314+
},
300315
"useState": {
301316
"prefix": "useState.$useState.🟨",
302317
"body": [

snippets/typescript.json

+15
Original file line numberDiff line numberDiff line change
@@ -297,6 +297,21 @@
297297
"description": "React Arrow Function Component with PropTypes",
298298
"scope": "javascript,typescript,javascriptreact,typescriptreact"
299299
},
300+
"hocComponent": {
301+
"prefix": "hoc.$hoc.🟨",
302+
"body": [
303+
"export default function ${1:${RELATIVE_FILEPATH/(^.+?(?=[\\/\\\\][^\\/\\\\]+[\\/\\\\][^\\/\\\\]+\\.[jt]sx?))|(\\.[jt]sx?$|[\\/\\\\](?:index|\\[).*|.+[\\/\\\\](?!(?:index|\\[))|[.\\-_\\/\\\\])|([\\w\\-_]*)/${3:/camelcase}/g}}(WrappedComponent) {$0",
304+
"\tconst Component = (props) => {",
305+
"\t\treturn <WrappedComponent {...props} />",
306+
"\t}",
307+
"",
308+
"\treturn Component",
309+
"}",
310+
""
311+
],
312+
"description": "React HOC",
313+
"scope": "javascript,typescript,javascriptreact,typescriptreact"
314+
},
300315
"tsReactFunctionalComp": {
301316
"prefix": "rfc.TS.$$rfc.🟦",
302317
"body": [

src/snippets/react.ts

+15-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
1+
import { FILENAME_PASCALCASE, FILENAME_CAMELCASE } from '../constants';
12
import { Snippet } from '../types';
23

3-
const { FILENAME_PASCALCASE } = require('../constants');
4-
54
export const reactFunctionalComp: Snippet = {
65
prefix: 'rfc',
76
body: [
@@ -125,3 +124,17 @@ export const reactArrowFunctionCompWithPropTypesChildren: Snippet = {
125124
],
126125
description: 'React Arrow Function Component with PropTypes',
127126
};
127+
128+
export const hocComponent: Snippet = {
129+
prefix: 'hoc',
130+
body: [
131+
`export default function \${1:${FILENAME_CAMELCASE}}(WrappedComponent) {$0`,
132+
'\tconst Component = (props) => {',
133+
'\t\treturn <WrappedComponent {...props} />',
134+
'\t}',
135+
'',
136+
'\treturn Component',
137+
'}',
138+
],
139+
description: 'React HOC',
140+
};

0 commit comments

Comments
 (0)