Skip to content

Commit 3148d38

Browse files
Add react snippets for javascript and typescript (nathanchapman#13)
Co-authored-by: Anthony Nichols <hi@anthonynichols.me>
1 parent c28944a commit 3148d38

File tree

3 files changed

+173
-5
lines changed

3 files changed

+173
-5
lines changed

README.md

Lines changed: 39 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ var ${0}
3333
##### `v=⇥` var assignment
3434

3535
```javascript
36-
var ${1:name} = ${2:value};
36+
var ${1:name} = ${2:value}
3737
```
3838

3939
##### `l⇥` let statement
@@ -45,13 +45,13 @@ let ${0}
4545
##### `l=⇥` let assignment
4646

4747
```javascript
48-
let ${1:name} = ${2:value};
48+
let ${1:name} = ${2:value}
4949
```
5050

5151
##### `dl=⇥` destructuring let assignment
5252

5353
```javascript
54-
let {${1:name}} = ${2:value};
54+
let {${1:name}} = ${2:value}
5555
```
5656

5757
##### `co⇥` const statement
@@ -63,13 +63,13 @@ const ${0}
6363
##### `co=⇥` const assignment
6464

6565
```javascript
66-
const ${1:name} = ${2:value};
66+
const ${1:name} = ${2:value}
6767
```
6868

6969
##### `dco=⇥` destructuring const assignment
7070

7171
```javascript
72-
const {${1:name}} = ${2:value};
72+
const {${1:name}} = ${2:value}
7373
```
7474

7575
#### Flow Control
@@ -755,3 +755,37 @@ process.nextTick(() => {
755755
```javascript
756756
'use strict'
757757
```
758+
759+
#### React (JS)
760+
761+
##### `propTypes⇥`
762+
763+
```javascript
764+
static propTypes = {$0}
765+
```
766+
767+
##### `defaultProps⇥`
768+
769+
```javascript
770+
static defaultProps = {$0}
771+
```
772+
773+
##### `getDerivedStateFromProps⇥`
774+
775+
```javascript
776+
static getDerivedStateFromProps(${1:nextProps}, ${2:prevState}) {$0}
777+
```
778+
779+
#### React (TS)
780+
781+
##### `defaultProps⇥`
782+
783+
```typescript
784+
static defaultProps: Partial<${1:${TM_FILENAME_BASE}Props}> = {$0}
785+
```
786+
787+
##### `getDerivedStateFromProps⇥`
788+
789+
```typescript
790+
static getDerivedStateFromProps(${1:nextProps}: ${3:${TM_FILENAME_BASE}${2:Props}}, ${4:prevState}: ${6:${TM_FILENAME_BASE}${5:State}}): Partial<${6:${TM_FILENAME_BASE}${5:State}}> {$0}
791+
```

snippets/jsx.json

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -473,5 +473,73 @@
473473
"prefix": "us",
474474
"body": "'use strict'",
475475
"description": "insert 'use strict' statement"
476+
},
477+
"component static prop types": {
478+
"prefix": "propTypes",
479+
"body": "static propTypes = {$0}",
480+
"description": "Component Static Prop Types"
481+
},
482+
"component static default props": {
483+
"prefix": "defaultProps",
484+
"body": "static defaultProps = {$0}",
485+
"description": "Component Static Default Props"
486+
},
487+
"component static get derived state from props": {
488+
"prefix": "getDerivedStateFromProps",
489+
"body": "static getDerivedStateFromProps(${1:nextProps}, ${2:prevState}) {$0}",
490+
"description": "Component Static Get Derived State From Props"
491+
},
492+
"component set state": {
493+
"prefix": "setState",
494+
"body": "this.setState($1)$0"
495+
},
496+
"component constructor": {
497+
"prefix": "constructor",
498+
"body": [
499+
"constructor(${1:props}) {",
500+
"\tsuper(${1:props})",
501+
"",
502+
"\t$4",
503+
"}"
504+
]
505+
},
506+
"component will mount": {
507+
"prefix": "componentWillMount",
508+
"body": "componentWillMount() {$0}",
509+
"description": "DEPRECATION WARNING [v16.3]: Use `componentDidMount` instead."
510+
},
511+
"component did mount": {
512+
"prefix": "componentDidMount",
513+
"body": "componentDidMount() {$0}"
514+
},
515+
"component will receive props": {
516+
"prefix": "componentWillReceiveProps",
517+
"body": "componentWillReceiveProps(${1:nextProps}) {$0}",
518+
"description": "DEPRECATION WARNING [v16.3]: Use `static getDerivedStateFromProps` instead."
519+
},
520+
"should component update": {
521+
"prefix": "shouldComponentUpdate",
522+
"body": "shouldComponentUpdate(${1:nextProps}, ${2:nextState}) {$0}"
523+
},
524+
"component will update": {
525+
"prefix": "componentWillUpdate",
526+
"body": "componentWillUpdate(${1:nextProps}, ${2:nextState}) {$0}",
527+
"description": "DEPRECATION WARNING [v16.3]: Use `componentDidUpdate` instead."
528+
},
529+
"component did update": {
530+
"prefix": "componentDidUpdate",
531+
"body": "componentDidUpdate(${1:nextProps}, ${2:state}) {$0}"
532+
},
533+
"component will unmount": {
534+
"prefix": "componentWillUnmount",
535+
"body": "componentWillUnmount() {$0}"
536+
},
537+
"component did catch": {
538+
"prefix": "componentDidCatch",
539+
"body": "componentDidCatch(${1:error}, ${2:errorInfo}) {$0}"
540+
},
541+
"component render": {
542+
"prefix": "render",
543+
"body": ["render() {", "\treturn ($0)", "}"]
476544
}
477545
}

snippets/tsx.json

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -473,5 +473,71 @@
473473
"prefix": "us",
474474
"body": "'use strict'",
475475
"description": "insert 'use strict' statement"
476+
},
477+
"component static prop types": {
478+
"prefix": "propTypes",
479+
"body": "static propTypes = {$0}",
480+
"description": "Component Static Prop Types"
481+
},
482+
"component static default props": {
483+
"prefix": "defaultProps",
484+
"body": "static defaultProps: Partial<${1:${TM_FILENAME_BASE}Props}> = {$0}"
485+
},
486+
"component static get derived state from props": {
487+
"prefix": "getDerivedStateFromProps",
488+
"body": "static getDerivedStateFromProps(${1:nextProps}: ${3:${TM_FILENAME_BASE}${2:Props}}, ${4:prevState}: ${6:${TM_FILENAME_BASE}${5:State}}): Partial<${6:${TM_FILENAME_BASE}${5:State}}> {$0}"
489+
},
490+
"component set state": {
491+
"prefix": "setState",
492+
"body": "this.setState($1)$0"
493+
},
494+
"component constructor": {
495+
"prefix": "constructor",
496+
"body": [
497+
"constructor(${1:props}: ${3:${TM_FILENAME_BASE}${2:Props}}) {",
498+
"\tsuper(${1:props})",
499+
"",
500+
"\t$4",
501+
"}"
502+
]
503+
},
504+
"component will mount": {
505+
"prefix": "componentWillMount",
506+
"body": "componentWillMount() {$0}",
507+
"description": "DEPRECATION WARNING [v16.3]: Use `componentDidMount` instead."
508+
},
509+
"component did mount": {
510+
"prefix": "componentDidMount",
511+
"body": "componentDidMount() {$0}"
512+
},
513+
"component will receive props": {
514+
"prefix": "componentWillReceiveProps",
515+
"body": "componentWillReceiveProps(${1:nextProps}: ${3:${TM_FILENAME_BASE}${2:Props}}) {$0}",
516+
"description": "DEPRECATION WARNING [v16.3]: Use `static getDerivedStateFromProps` instead."
517+
},
518+
"should component update": {
519+
"prefix": "shouldComponentUpdate",
520+
"body": "shouldComponentUpdate(${1:nextProps}: ${3:${TM_FILENAME_BASE}${2:Props}}, ${4:nextState}: ${6:${TM_FILENAME_BASE}${5:State}}) {$0}"
521+
},
522+
"component will update": {
523+
"prefix": "componentWillUpdate",
524+
"body": "componentWillUpdate(${1:nextProps}: ${3:${TM_FILENAME_BASE}${2:Props}}, ${4:nextState}: ${6:${TM_FILENAME_BASE}${5:State}}) {$0}",
525+
"description": "DEPRECATION WARNING [v16.3]: Use `componentDidUpdate` instead."
526+
},
527+
"component did update": {
528+
"prefix": "componentDidUpdate",
529+
"body": "componentDidUpdate(${1:nextProps}: ${3:${TM_FILENAME_BASE}${2:Props}}, ${4:nextState}: ${6:${TM_FILENAME_BASE}${5:State}}) {$0}"
530+
},
531+
"component will unmount": {
532+
"prefix": "componentWillUnmount",
533+
"body": "componentWillUnmount() {$0}"
534+
},
535+
"component did catch": {
536+
"prefix": "componentDidCatch",
537+
"body": "componentDidCatch(${1:error}: Error, ${2:errorInfo}: React.ErrorInfo) {$0}"
538+
},
539+
"component render": {
540+
"prefix": "render",
541+
"body": ["render() {", "\treturn ($0)", "}"]
476542
}
477543
}

0 commit comments

Comments
 (0)