Skip to content

Commit a5d4511

Browse files
authored
Merge pull request #25 from alDuncanson/21-new-react-hooks-snippets
21 new react hooks snippets
2 parents 90c4516 + 047dda1 commit a5d4511

File tree

3 files changed

+151
-60
lines changed

3 files changed

+151
-60
lines changed

README.md

+59-23
Original file line numberDiff line numberDiff line change
@@ -4,47 +4,83 @@
44

55
# React Hooks Snippets
66

7-
React Hooks Snippets is a [Visual Studio Code](https://code.visualstudio.com/) extension to make writing ReactJS [Hooks](https://react.dev/reference/react/hooks) easier and faster!
7+
![Visual Studio Marketplace Installs](https://img.shields.io/visual-studio-marketplace/i/AlDuncanson.react-hooks-snippets)
8+
![Visual Studio Marketplace Rating](https://img.shields.io/visual-studio-marketplace/r/AlDuncanson.react-hooks-snippets)
9+
![Visual Studio Marketplace Version](https://img.shields.io/visual-studio-marketplace/v/AlDuncanson.react-hooks-snippets)
10+
![GitHub Repo stars](https://img.shields.io/github/stars/alDuncanson/react-hooks-snippets)
11+
![GitHub forks](https://img.shields.io/github/forks/alDuncanson/react-hooks-snippets)
812

13+
A [Visual Studio Code](https://code.visualstudio.com/) extension that adds snippet functionality for [React Hooks](https://react.dev/reference/react/hooks).
914

10-
## Supported Snippets
15+
> Now updated to support all of the new hooks introduced in [React v19](https://react.dev/blog/2024/12/05/react-19)!
1116
17+
## Supported Hooks
18+
19+
### State Hooks
1220
| Prefix | Snippet |
1321
| ------------- | ------------- |
1422
| `ush` | `useState` |
15-
| `ueh` | `useEffect` |
23+
| `urdh` | `useReducer` |
24+
25+
### Context Hooks
26+
| Prefix | Snippet |
27+
| ------------- | ------------- |
1628
| `uch` | `useContext` |
17-
| `ucbh` | `useCallback` |
18-
| `umh` | `useMemo` |
19-
| `irh` | `import React` (and common hooks) |
29+
30+
### Ref Hooks
31+
| Prefix | Snippet |
32+
| ------------- | ------------- |
2033
| `urh` | `useRef` |
21-
| `urdh` | `useReducer` |
22-
| `irrh` | import react redux hooks |
23-
| `uss` | `useSelector` |
24-
| `usdf` | `useDispatch` |
25-
| `usd` | then use your `dispatch` |
34+
| `uihh` | `useImperativeHandle` |
2635

36+
### Effect Hooks
37+
| Prefix | Snippet |
38+
| ------------- | ------------- |
39+
| `ueh` | `useEffect` |
40+
| `uleh` | `useLayoutEffect` |
41+
| `uieh` | `useInsertionEffect` |
2742

28-
## Add to your project
43+
### Performance Hooks
44+
| Prefix | Snippet |
45+
| ------------- | ------------- |
46+
| `umh` | `useMemo` |
47+
| `ucbh` | `useCallback` |
48+
| `uth` | `useTransition` |
49+
| `udvh` | `useDeferredValue` |
2950

30-
There are 2 ways you can add React Hooks Snippets to your project:
51+
### React Dom Hooks
52+
| Prefix | Snippet |
53+
| ------------- | ------------- |
54+
| `ufsh` | `useFormStatus` |
3155

32-
#### By command
33-
Launch VS Code Quick Open (`Ctrl+P`), paste `ext install AlDuncanson.react-hooks-snippets`, and press enter.
56+
### Other Hooks
57+
| Prefix | Snippet |
58+
| ------------- | ------------- |
59+
| `udbvh` | `useDebugValue` |
60+
| `uidh` | `useId` |
61+
| `usesh` | `useSyncExternalStore` |
62+
| `uash` | `useActionState` |
63+
| `uoh` | `useOptimistic` |
3464

35-
#### By the Extension Marketplace
36-
Launch VS Code Extension Marketplace (Ctrl+Shift+X), search for `React Hooks Snippets`, and look for my logo!
65+
## Install
3766

67+
Add the React Hooks Snippets extension to VS Code using one of the following methods:
3868

39-
## Contributing
69+
### By command
70+
Launch VS Code Quick Open (`Ctrl+P`), paste `ext install AlDuncanson.react-hooks-snippets`, and press enter.
4071

41-
There are two ways to contribute:
72+
### By the Marketplace UI
73+
Launch VS Code Extension Marketplace UI (`Ctrl+Shift+X`), search for `React Hooks Snippets`, and look for my logo!
4274

43-
#### Code
44-
Submit a pull request with your proposed fixes, changes, and/or improvements. All are welcome!
75+
### By the Marketplace website
76+
Visit the extension's [Visual Studio Marketplace page](https://marketplace.visualstudio.com/items?itemName=AlDuncanson.react-hooks-snippets) and click `Install`.
4577

46-
#### Coffee
47-
<a href='https://www.buymeacoffee.com/alduncanson' target='_blank'><img src='https://cdn.buymeacoffee.com/buttons/default-orange.png' alt='Buy Me A Coffee' height='34' width='144'></a>
4878

4979
## License
5080
Usage is provided under the [MIT License](https://opensource.org/licenses/MIT). See [LICENSE.txt](https://github.com/alDuncanson/react-hooks-snippets/blob/master/LICENSE.txt) for the full details.
81+
82+
## Support My Work
83+
84+
If you like this extension, please consider supporting me by buying me a coffee!
85+
86+
<a href='https://www.buymeacoffee.com/alduncanson' target='_blank'><img src='https://cdn.buymeacoffee.com/buttons/default-orange.png' alt='Buy Me A Coffee' height='34' width='144'></a>

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"name": "react-hooks-snippets",
33
"displayName": "React Hooks Snippets",
44
"description": "Code snippets for React Hooks",
5-
"version": "1.3.0",
5+
"version": "1.4.0",
66
"icon": "icon.png",
77
"publisher": "AlDuncanson",
88
"repository": {

snippets/snippets.json

+91-36
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,38 @@
66
],
77
"description": "React useState() hook"
88
},
9+
"useReducer": {
10+
"prefix": "urdh",
11+
"body": [
12+
"const [${1:state},${2: dispatch}] = useReducer(${3:reducer}, ${4:initialArg}, ${5:init});"
13+
],
14+
"description": "React useReducer() hook"
15+
},
16+
"useContext": {
17+
"prefix": "uch",
18+
"body": [
19+
"const $1 = useContext($2);$0"
20+
],
21+
"description": "React useContext() hook"
22+
},
23+
"useRef": {
24+
"prefix": "urh",
25+
"body": [
26+
"const $1 = useRef($2);$0"
27+
],
28+
"description": "React useRef() hook"
29+
},
30+
"useImperativeHandle": {
31+
"prefix": "uihh",
32+
"body": [
33+
"useImperativeHandle(ref, () => {",
34+
"\treturn {",
35+
"\t\t$1",
36+
"\t}",
37+
"}, [$2]);$0"
38+
],
39+
"description": "React useImperativeHandle() hook"
40+
},
941
"useEffect": {
1042
"prefix": "ueh",
1143
"body": [
@@ -18,12 +50,30 @@
1850
],
1951
"description": "React useEffect() hook"
2052
},
21-
"useContext": {
22-
"prefix": "uch",
53+
"useLayoutEffect": {
54+
"prefix": "uleh",
2355
"body": [
24-
"const $1 = useContext($2);$0"
56+
"useLayoutEffect(() => {",
57+
"\t$1",
58+
"}, [${2}]);$0"
2559
],
26-
"description": "React useContext() hook"
60+
"description": "React useLayoutEffect() hook"
61+
},
62+
"useInsertionEffect": {
63+
"prefix": "uieh",
64+
"body": [
65+
"useInsertionEffect(() => {",
66+
"\t$1",
67+
"}, [${2}]);$0"
68+
],
69+
"description": "React useInsertionEffect() hook"
70+
},
71+
"useMemo": {
72+
"prefix": "umh",
73+
"body": [
74+
"const ${1:memoizedValue} = useMemo(() => ${2:computeExpensiveValue}(${3:a}, ${4:b}), [${5:a}, ${6:b}]);$0"
75+
],
76+
"description": "React useMemo() hook"
2777
},
2878
"useCallback": {
2979
"prefix": "ucbh",
@@ -37,55 +87,60 @@
3787
],
3888
"description": "React useCallback() hook"
3989
},
40-
"useMemo": {
41-
"prefix": "umh",
90+
"useTransition": {
91+
"prefix": "uth",
4292
"body": [
43-
"const ${1:memoizedValue} = useMemo(() => ${2:computeExpensiveValue}(${3:a}, ${4:b}), [${5:a}, ${6:b}]);$0"
93+
"const [isPending, startTransition] = useTransition();$0"
4494
],
45-
"description": "React useMemo() hook"
95+
"description": "React useTransition() hook"
4696
},
47-
"import react hooks": {
48-
"prefix": "irh",
97+
"useDeferredValue": {
98+
"prefix": "udvh",
4999
"body": [
50-
"import React, { useState, useContext, useEffect, useCallback, useMemo } from 'react';"
51-
]
100+
"const ${1:deferredValue} = useDeferredValue(${2:value});$0"
101+
],
102+
"description": "React useDeferredValue() hook"
52103
},
53-
"useRef": {
54-
"prefix": "urh",
104+
"useFormStatus": {
105+
"prefix": "ufsh",
55106
"body": [
56-
"const $1 = useRef($2);$0"
107+
"const { ${1:pending}, ${2:data}, ${3:method}, ${4:action} } = useFormStatus();$0"
57108
],
58-
"description": "React useRef() hook"
109+
"description": "React Dom useFormStatus() hook"
59110
},
60-
"useReducer": {
61-
"prefix": "urdh",
111+
"useDebugValue": {
112+
"prefix": "udbvh",
62113
"body": [
63-
"const [${1:state},${2: dispatch}] = useReducer(${3:reducer}, ${4:initialArg}, ${5:init});"
114+
"useDebugValue(${1:value});$0"
64115
],
65-
"description": "React useReducer() hook"
116+
"description": "React useDebugValue() hook"
66117
},
67-
"import react-redux hooks": {
68-
"prefix": "irrh",
118+
"useId": {
119+
"prefix": "uidh",
69120
"body": [
70-
"import { useSelector, useDispatch } from 'react-redux';"
71-
]
121+
"const ${1:id} = useId();$0"
122+
],
123+
"description": "React useId() hook"
72124
},
73-
"useSelector": {
74-
"prefix": "uss",
125+
"useSyncExternalStore": {
126+
"prefix": "usesh",
75127
"body": [
76-
"const $1 = useSelector(state => state.$1);"
77-
]
128+
"const ${1:snapshot} = useSyncExternalStore(${2:subscribe}, ${3:getSnapshot}, ${4:getServerSnapshot});$0"
129+
],
130+
"description": "React useSyncExternalStore() hook"
78131
},
79-
"useDispatchFunction": {
80-
"prefix": "usdf",
132+
"useActionState": {
133+
"prefix": "uash",
81134
"body": [
82-
"const $1 = useDispatch($2);$3"
83-
]
135+
"const [${1:state}, ${2:formAction}, ${3:isPending}] = useActionState(${4:fn}, ${5:initialState});$0"
136+
],
137+
"description": "React useActionState() hook"
84138
},
85-
"useDispatch": {
86-
"prefix": "usd",
139+
"useOptimistic": {
140+
"prefix": "uoh",
87141
"body": [
88-
"const $1 = $2 => dispatch($3);"
89-
]
142+
"const [${1:optimisticState}, ${2:addOptimistic}] = useOptimistic(${3:state}, ${4:updateFn});$0"
143+
],
144+
"description": "React useOptimistic() hook"
90145
}
91146
}

0 commit comments

Comments
 (0)