Skip to content

Commit 86af3f9

Browse files
committed
add react hook snippets
1 parent 11ab7c6 commit 86af3f9

File tree

5 files changed

+379
-307
lines changed

5 files changed

+379
-307
lines changed

README.md

Lines changed: 19 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -505,13 +505,13 @@ return ${0}
505505
#### `rt⇥` return this
506506

507507
```js
508-
return this;
508+
return this
509509
```
510510

511511
#### `rn⇥` return null
512512

513513
```js
514-
return null;
514+
return null
515515
```
516516

517517
#### `ro⇥` return new object
@@ -641,7 +641,7 @@ import ${1:*} as ${2:name} from '${3:module}'
641641
#### `id⇥` module import destructuring
642642

643643
```js
644-
import { $1 } from "${2:module}";
644+
import { $1 } from '${2:module}'
645645
```
646646

647647
### BDD testing (Mocha, Jasmine, etc.)
@@ -755,9 +755,9 @@ ${1:document}.removeEventListener('${2:event}', ${3:listener})
755755
#### `evc` dom event cancel default and propagation
756756

757757
```js
758-
ev.preventDefault();
759-
ev.stopPropagation();
760-
return false;
758+
ev.preventDefault()
759+
ev.stopPropagation()
760+
return false
761761
```
762762

763763
#### `gi⇥` getElementById
@@ -864,7 +864,7 @@ function (err, ${1:value}) {
864864
#### `rq⇥` require a module
865865

866866
```js
867-
require("${1:module}");
867+
require('${1:module}')
868868
```
869869

870870
#### `cr⇥` require and assign a module
@@ -895,22 +895,22 @@ ${1:emitter}.on('${2:event}', (${3:arguments}) => {
895895

896896
### Miscellaneous
897897

898-
#### `us` use strict
898+
#### `uss` use strict
899899

900900
```js
901-
"use strict";
901+
'use strict'
902902
```
903903

904904
#### `js⇥` JSON Stringify
905905

906906
```js
907-
JSON.stringify($0);
907+
JSON.stringify($0)
908908
```
909909

910910
#### `jp⇥` JSON Parse
911911

912912
```js
913-
JSON.parse($0);
913+
JSON.parse($0)
914914
```
915915

916916
#### `a⇥` await
@@ -1012,7 +1012,14 @@ Below is a list of all available snippets and the triggers of each one. The **
10121012
| `ssf→` | `this.setState with function as parameter` |
10131013
| `tp` | `this.props` |
10141014
| `ts` | `this.state` |
1015-
| `bnd→` | `binds the this of method inside the constructor` |
1015+
| `us` | `useState` |
1016+
| `ue` | `useEffect` |
1017+
| `ur` | `useRef` |
1018+
| `uc` | `useContext` |
1019+
| `ume` | `useMemo` |
1020+
| ------- | ---------------------------------------------------------------- |
1021+
| `uq` | `useQuery` |
1022+
| `um` | `useMutation` |
10161023

10171024
There are also snippets to be triggered with a text selection(trigger via insert snippet command):
10181025

package.json

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
"displayName": "JavaScript standardjs styled snippets",
44
"publisher": "capaj",
55
"icon": "images/javascript.png",
6-
"version": "0.8.4",
6+
"version": "0.8.5",
77
"description": "standardjs styled javascript snippets for visual studio code",
88
"repository": {
99
"type": "git",
@@ -49,6 +49,14 @@
4949
{
5050
"language": "typescriptreact",
5151
"path": "./snippets/react.json"
52+
},
53+
{
54+
"language": "javascriptreact",
55+
"path": "./snippets/apollo.json"
56+
},
57+
{
58+
"language": "typescriptreact",
59+
"path": "./snippets/apollo.json"
5260
}
5361
]
5462
}

snippets/apollo.json

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
{
2+
"useQuery": {
3+
"prefix": "uq",
4+
"body": ["const { data, loading } = useQuery(gql`${1:query}`)"],
5+
"description": "useQuery"
6+
},
7+
"useMutation": {
8+
"prefix": "um",
9+
"body": [
10+
"const ${1:mutationName} = useMutation(gql`${1:query}`, {",
11+
" variables: ${1:vars},",
12+
"});"
13+
],
14+
"description": "useMutation"
15+
}
16+
}

snippets/javascript.json

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -239,6 +239,10 @@
239239
"prefix": "cd",
240240
"body": "const { ${2:prop} } = ${1:value}"
241241
},
242+
"const statement from array destructuring": {
243+
"prefix": "cad",
244+
"body": "const [ ${2:prop} ] = ${1:value}"
245+
},
242246
"const assignment awaited": {
243247
"prefix": "ca",
244248
"body": "const ${1:name} = await ${2:value}"
@@ -452,7 +456,7 @@
452456
"body": "constructor () {\n\t${0}\n}"
453457
},
454458
"use strict": {
455-
"prefix": "us",
459+
"prefix": "uss",
456460
"body": "'use strict'"
457461
},
458462
"JSON.stringify()": {

0 commit comments

Comments
 (0)