Skip to content

Commit 82acd45

Browse files
AmelloAsterxhe
and
xhe
authored
feat: add useMemo snip (#68)
Co-authored-by: xhe <[email protected]>
1 parent 69d90ac commit 82acd45

File tree

4 files changed

+42
-17
lines changed

4 files changed

+42
-17
lines changed

Diff for: .gitignore

+2
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,4 @@
11
node_modules
22
package-lock.json
3+
4+
.DS_Store

Diff for: packages/vscode/README.md

+26-14
Original file line numberDiff line numberDiff line change
@@ -51,25 +51,31 @@
5151
useEffect(() => {}, []);
5252
```
5353

54-
7. `rus` (useState hook)
54+
7. `rum` (useMemo hook)
5555

5656
```jsx
57-
const [state, setState] = useState(initialValue);
57+
useMemo(() => {}, []);
5858
```
5959

60-
8. `ruc` (useContext hook)
60+
8. `rus` (useState hook)
6161

6262
```jsx
63-
const value = useContext(myContext);
63+
const [state, setState] = useState(initialValue);
6464
```
6565

66-
9. `rucb` (useCallback hook)
66+
9. `ruc` (useContext hook)
6767

6868
```jsx
69-
const handleCallback = useCallback(() => {}, []);
69+
const value = useContext(myContext);
7070
```
7171

72-
10. `rur` (useRef hook)
72+
10. `rucb` (useCallback hook)
73+
74+
```jsx
75+
const handleCallback = useCallback(() => {}, []);
76+
```
77+
78+
11. `rur` (useRef hook)
7379

7480
```jsx
7581
const refContainer = useRef(initialValue);
@@ -80,13 +86,13 @@
8086
1. `rfcet` (React functional component)
8187

8288
```tsx
83-
import React from "react";
89+
import type { FC } from "react";
8490
8591
interface Props {}
8692
87-
function Component({}: Props) {
93+
const Component: FC<Props> = () => {
8894
return <div></div>;
89-
}
95+
};
9096
9197
export default Component;
9298
```
@@ -97,25 +103,31 @@
97103
useEffect(() => {}, []);
98104
```
99105

100-
3. `rust` (useState hook)
106+
3. `rumt` (useMemo hook)
107+
108+
```tsx
109+
useMemo<>(() => {}, []);
110+
```
111+
112+
4. `rust` (useState hook)
101113

102114
```tsx
103115
const [state, setState] = useState(initialValue);
104116
```
105117

106-
4. `ruct` (useContext hook)
118+
5. `ruct` (useContext hook)
107119

108120
```tsx
109121
const value = useContext(myContext);
110122
```
111123

112-
5. `rucbt` (useCallback hook)
124+
6. `rucbt` (useCallback hook)
113125

114126
```jsx
115127
const handleCallback = useCallback(() => {}, []);
116128
```
117129

118-
6. `rurt` (useRef hook)
130+
7. `rurt` (useRef hook)
119131

120132
```tsx
121133
const refContainer = useRef(initialValue);

Diff for: packages/vscode/snippets/react-javascript.json

+5
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,11 @@
3434
"body": ["useEffect(() => {", "\t$1", "}, []);"],
3535
"description": "JavaScript: useEffect hook"
3636
},
37+
"rum": {
38+
"prefix": "rum",
39+
"body": ["useMemo(() => {", "\t$1", "}, []);"],
40+
"description": "JavaScript: useMemo hook"
41+
},
3742
"rus": {
3843
"prefix": "rus",
3944
"body": ["const [${1}, set${1}] = useState(${2});"],

Diff for: packages/vscode/snippets/react-typescript.json

+9-3
Original file line numberDiff line numberDiff line change
@@ -22,13 +22,14 @@
2222
"rfct": {
2323
"prefix": "rfct",
2424
"body": [
25-
"import type { FC } from 'react'",
25+
"import type { FC } from 'react';",
2626
"",
2727
"interface ${TM_FILENAME_BASE}Props {}",
2828
"",
29-
"export const $TM_FILENAME_BASE: FC<${TM_FILENAME_BASE}Props> = ({$2}) => {",
29+
"const $TM_FILENAME_BASE: FC<${TM_FILENAME_BASE}Props> = ({$2}) => {",
3030
"\t\treturn ($3);",
31-
"}"
31+
"}",
32+
"export default $TM_FILENAME_BASE;"
3233
],
3334
"description": "Typescript: React functional component"
3435
},
@@ -37,6 +38,11 @@
3738
"body": ["useEffect(() => {", "\t$1", "}, []);"],
3839
"description": "TypeScript: useEffect hook"
3940
},
41+
"rumt": {
42+
"prefix": "rumt",
43+
"body": ["useMemo<${1}>(() => {", "\t$2", "}, []);"],
44+
"description": "Typescript: useMemo hook"
45+
},
4046
"rust": {
4147
"prefix": "rust",
4248
"body": ["const [${1}, set${1}] = useState(${2});"],

0 commit comments

Comments
 (0)