2
2
# React snippets
3
3
#
4
4
5
- snippet cs " React.addons.classSet" b
6
- var cx = React.addons.classSet;
7
- endsnippet
8
-
9
- snippet cdm " component did mount" b
10
- componentDidMount: function() {
5
+ snippet cdm " Component did mount" b
6
+ componentDidMount() {
11
7
${1}
12
- }, $0
8
+ }$0
13
9
endsnippet
14
10
15
- snippet cdup " component did update" b
16
- componentDidUpdate: function (prevProps, prevState) {
11
+ snippet cdup " Component did update" b
12
+ componentDidUpdate(prevProps, prevState) {
17
13
${1}
18
- }, $0
14
+ }$0
19
15
endsnippet
20
16
21
- snippet cwm " component will mount" b
22
- componentWillMount: function () {
17
+ snippet cwm " Component will mount" b
18
+ componentWillMount() {
23
19
${1}
24
- }, $0
20
+ }$0
25
21
endsnippet
26
22
27
- snippet cwr " component will receive props" b
28
- componentWillReceiveProps: function (nextProps) {
23
+ snippet cwr " Component will receive props" b
24
+ componentWillReceiveProps(nextProps) {
29
25
${1}
30
- }, $0
26
+ }$0
31
27
endsnippet
32
28
33
- snippet cwun " component will unmount" b
34
- componentWillUnmount: function () {
29
+ snippet cwun " Component will unmount" b
30
+ componentWillUnmount() {
35
31
${1}
36
- }, $0
32
+ }$0
37
33
endsnippet
38
34
39
- snippet cwu " component will update" b
40
- componentWillUpdate: function (nextProps, nextState) {
35
+ snippet cwu " Component will update" b
36
+ componentWillUpdate(nextProps, nextState) {
41
37
${1}
42
- },$0
43
- endsnippet
44
-
45
- snippet cx
46
- cx({
47
- ${1} : ${2}
48
- });
38
+ }$0
49
39
endsnippet
50
40
51
- snippet fup
52
- forceUpdate(${1: callback } );
41
+ snippet fup " Force update "
42
+ forceUpdate(${1: callback } )
53
43
endsnippet
54
44
55
- snippet gdp " get default props" b
56
- getDefaultProps: function () {
45
+ snippet gdp " Get default props" b
46
+ getDefaultProps() {
57
47
return {
58
48
${1}
59
- };
60
- }, $0
49
+ }
50
+ }$0
61
51
endsnippet
62
52
63
- snippet gis " get initial state" b
64
- getInitialState: function () {
53
+ snippet gis " Get initial state" b
54
+ getInitialState() {
65
55
return {
66
56
${1} : ${2}
67
- };
68
- }, $0
57
+ }
58
+ }$0
69
59
endsnippet
70
60
71
- snippet ism " is mounted"
61
+ snippet ism " Is mounted"
72
62
isMounted()
73
63
endsnippet
74
64
75
- snippet jsx " define jsx dom" b
65
+ snippet jsx " Define jsx dom" b
76
66
/**
77
67
* @jsx React.DOM
78
68
*/
79
69
80
- var React = require('react');
81
- }
82
- var ${2: ClassName } = React.createClass({
70
+ import React from 'react';
83
71
84
- render: function() {
72
+ let ${2: ClassName } = React.createClass({
73
+
74
+ render() {
85
75
return (
86
76
${VISUAL}$4
87
77
);
@@ -95,50 +85,72 @@ endsnippet
95
85
snippet pt " propTypes" b
96
86
propTypes: {
97
87
${1} : React.PropTypes.${2: string }
98
- },
88
+ }
99
89
endsnippet
100
90
101
- snippet rcc " create class/component " b
102
- var ${1: ClassName } = React.createClass({
91
+ snippet rcc " React.createClass " b
92
+ let ${1: ClassName } = React.createClass({
103
93
104
- render: function () {
94
+ render() {
105
95
return (
106
96
${VISUAL}$2
107
- );
97
+ )
108
98
}
109
99
110
- });
100
+ })
111
101
$0
112
102
endsnippet
113
103
114
- snippet ren
115
- render: function() {
104
+ snippet rcx " Extends React.Component" b
105
+ class ${1: ClassName } extends React.Component {
106
+ render(){
107
+ return (
108
+ $2
109
+ )
110
+ }
111
+ }
112
+ endsnippet
113
+
114
+ snippet ren " render"
115
+ render() {
116
116
return (
117
117
${1: <div /> }
118
- );
118
+ )
119
119
}$0
120
120
endsnippet
121
121
122
- snippet sst " set state" b
122
+ snippet sst " Set state" b
123
123
this.setState({
124
124
${1} : ${2}
125
- }); $0
125
+ })$0
126
126
endsnippet
127
127
128
- snippet scu " should component update"
129
- shouldComponentUpdate: function (nextProps, nextState) {
128
+ snippet scu " Should component update"
129
+ shouldComponentUpdate(nextProps, nextState) {
130
130
${1}
131
- }, $0
131
+ }$0
132
132
endsnippet
133
133
134
- snippet props " get property" i
134
+ snippet props " Get property" i
135
135
this.props.${1}
136
136
endsnippet
137
137
138
- snippet state " get state" i
138
+ snippet state " Get state" i
139
139
this.state.${1}
140
140
endsnippet
141
141
142
- snippet trp
143
- this.transferPropsTo(${VISUAL}$0 );
142
+ snippet trp " Transfer props to"
143
+ this.transferPropsTo(${VISUAL}$0 )
144
+ endsnippet
145
+
146
+ # This snippet will only works if the keyword 'con' is the first word of line
147
+ snippet con " Constructor for React.Component" b
148
+ constructor(props, context) {
149
+ super(props, context)
150
+
151
+ this.state = {
152
+ $1 : $2
153
+ }
154
+ }$0
155
+
144
156
endsnippet
0 commit comments