Skip to content

Commit

Permalink
feat: add useMemo snip (#68)
Browse files Browse the repository at this point in the history
Co-authored-by: xhe <x.b.he@accenture.com>
  • Loading branch information
AmelloAster and xhe committed May 22, 2022
1 parent 69d90ac commit 82acd45
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 17 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
node_modules
package-lock.json

.DS_Store
40 changes: 26 additions & 14 deletions packages/vscode/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,25 +51,31 @@
useEffect(() => {}, []);
```

7. `rus` (useState hook)
7. `rum` (useMemo hook)

```jsx
const [state, setState] = useState(initialValue);
useMemo(() => {}, []);
```

8. `ruc` (useContext hook)
8. `rus` (useState hook)

```jsx
const value = useContext(myContext);
const [state, setState] = useState(initialValue);
```

9. `rucb` (useCallback hook)
9. `ruc` (useContext hook)

```jsx
const handleCallback = useCallback(() => {}, []);
const value = useContext(myContext);
```

10. `rur` (useRef hook)
10. `rucb` (useCallback hook)

```jsx
const handleCallback = useCallback(() => {}, []);
```

11. `rur` (useRef hook)

```jsx
const refContainer = useRef(initialValue);
Expand All @@ -80,13 +86,13 @@
1. `rfcet` (React functional component)

```tsx
import React from "react";
import type { FC } from "react";

interface Props {}

function Component({}: Props) {
const Component: FC<Props> = () => {
return <div></div>;
}
};

export default Component;
```
Expand All @@ -97,25 +103,31 @@
useEffect(() => {}, []);
```

3. `rust` (useState hook)
3. `rumt` (useMemo hook)

```tsx
useMemo<>(() => {}, []);
```

4. `rust` (useState hook)

```tsx
const [state, setState] = useState(initialValue);
```

4. `ruct` (useContext hook)
5. `ruct` (useContext hook)

```tsx
const value = useContext(myContext);
```

5. `rucbt` (useCallback hook)
6. `rucbt` (useCallback hook)

```jsx
const handleCallback = useCallback(() => {}, []);
```

6. `rurt` (useRef hook)
7. `rurt` (useRef hook)

```tsx
const refContainer = useRef(initialValue);
Expand Down
5 changes: 5 additions & 0 deletions packages/vscode/snippets/react-javascript.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,11 @@
"body": ["useEffect(() => {", "\t$1", "}, []);"],
"description": "JavaScript: useEffect hook"
},
"rum": {
"prefix": "rum",
"body": ["useMemo(() => {", "\t$1", "}, []);"],
"description": "JavaScript: useMemo hook"
},
"rus": {
"prefix": "rus",
"body": ["const [${1}, set${1}] = useState(${2});"],
Expand Down
12 changes: 9 additions & 3 deletions packages/vscode/snippets/react-typescript.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,14 @@
"rfct": {
"prefix": "rfct",
"body": [
"import type { FC } from 'react'",
"import type { FC } from 'react';",
"",
"interface ${TM_FILENAME_BASE}Props {}",
"",
"export const $TM_FILENAME_BASE: FC<${TM_FILENAME_BASE}Props> = ({$2}) => {",
"const $TM_FILENAME_BASE: FC<${TM_FILENAME_BASE}Props> = ({$2}) => {",
"\t\treturn ($3);",
"}"
"}",
"export default $TM_FILENAME_BASE;"
],
"description": "Typescript: React functional component"
},
Expand All @@ -37,6 +38,11 @@
"body": ["useEffect(() => {", "\t$1", "}, []);"],
"description": "TypeScript: useEffect hook"
},
"rumt": {
"prefix": "rumt",
"body": ["useMemo<${1}>(() => {", "\t$2", "}, []);"],
"description": "Typescript: useMemo hook"
},
"rust": {
"prefix": "rust",
"body": ["const [${1}, set${1}] = useState(${2});"],
Expand Down

0 comments on commit 82acd45

Please sign in to comment.