Skip to content

Commit b7bc0ef

Browse files
committed
update: react documentation
1 parent ea9d7fd commit b7bc0ef

File tree

3 files changed

+120
-29
lines changed

3 files changed

+120
-29
lines changed

snippets/js/libraries/react/lifecycle/README.md

Lines changed: 23 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,41 +3,57 @@
33
### [jr.cdmount] componentDidMount
44

55
```javascript
6-
6+
componentDidMount: function () {
7+
// invoked once (client-only), after initial 'render'
8+
// good for AJAX, setTimeout, setInterval
9+
}
710
```
811

912
### [jr.cdupdate] componentDidUpdate
1013

1114
```javascript
12-
15+
componentDidUpdate: function (prevProps, prevState) {
16+
// invoked immediately after DOM updates, not for initial 'render'
17+
}
1318
```
1419

1520
### [jr.cwmount] componentWillMount
1621

1722
```javascript
18-
23+
componentWillMount: function () {
24+
// invoked once, before initial 'render'
25+
}
1926
```
2027

2128
### [jr.cwrprops] componentWillReceiveProps
2229

2330
```javascript
24-
31+
componentWillReceiveProps: function (nextProps) {
32+
// invoked when component is receiving props, not for initial 'render'
33+
}
2534
```
2635

2736
### [jr.cwunmount] componentWillUnmount
2837

2938
```javascript
30-
39+
componentWillUnmount: function () {
40+
// invoked immediately before a component is unmounted from the DOM
41+
}
3142
```
3243

3344
### [jr.cwupdate] componentWillUpdate
3445

3546
```javascript
36-
47+
componentWillUpdate: function (nextProps, nextState) {
48+
// invoked immediately before rendering with new props or state, not for initial 'render'
49+
// see componentWillReceiveProps if you need to call setState
50+
}
3751
```
3852

3953
### [jr.scupdate] shouldComponentUpdate
4054

4155
```javascript
42-
56+
shouldComponentUpdate: function (nextProps, nextState) {
57+
// invoked before rendering with new props, not for initial 'render'
58+
}
4359
```

snippets/js/libraries/react/prop-types/README.md

Lines changed: 78 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -3,89 +3,152 @@
33
### [jr.ptany] PropTypes.any
44

55
```javascript
6-
6+
{
7+
requiredAny: React.PropTypes.any.isRequired
8+
}
79
```
810

911
### [jr.ptarrayof] PropTypes.arrayOf
1012

1113
```javascript
12-
14+
{
15+
optionalArrayOf: React.PropTypes.arrayOf(React.PropTypes.string),
16+
requiredArrayOf: React.PropTypes.arrayOf(React.PropTypes.string).isRequired
17+
}
1318
```
1419

1520
### [jr.ptarray] PropTypes.array
1621

1722
```javascript
18-
23+
{
24+
optionalArray: React.PropTypes.array,
25+
requiredArray: React.PropTypes.array.isRequired
26+
}
1927
```
2028

2129
### [jr.ptbool] PropTypes.bool
2230

2331
```javascript
24-
32+
{
33+
optionalBoolean: React.PropTypes.bool,
34+
requiredBoolean: React.PropTypes.bool.isRequired
35+
}
2536
```
2637

2738
### [jr.ptelement] PropTypes.element
2839

2940
```javascript
30-
41+
{
42+
optionalElement: React.PropTypes.element,
43+
requiredElement: React.PropTypes.element.isRequired
44+
}
3145
```
3246

3347
### [jr.ptfunc] PropTypes.func
3448

3549
```javascript
36-
50+
{
51+
optionalFunction: React.PropTypes.func,
52+
requiredFunction: React.PropTypes.func.isRequired
53+
}
3754
```
3855

3956
### [jr.ptiof] PropTypes.instanceOf
4057

4158
```javascript
42-
59+
{
60+
optionalClass: React.PropTypes.instanceOf(MyClass),
61+
requiredClass: React.PropTypes.instanceOf(MyClass).isRequired
62+
}
4363
```
4464

4565
### [jr.ptnode] PropTypes.node
4666

4767
```javascript
48-
68+
{
69+
optionalNode: React.PropTypes.node,
70+
requiredNode: React.PropTypes.node.isRequired
71+
};
4972
```
5073

5174
### [jr.ptnumber] PropTypes.number
5275

5376
```javascript
54-
77+
{
78+
optionalNumber: React.PropTypes.number,
79+
requiredNumber: React.PropTypes.number.isRequired
80+
}
5581
```
5682

5783
### [jr.ptobjectof] PropTypes.objectOf
5884

5985
```javascript
60-
86+
{
87+
optionalObjectOf: React.PropTypes.objectOf(React.PropTypes.string),
88+
requiredObjectOf: React.PropTypes.objectOf(React.PropTypes.string).isRequired
89+
}
6190
```
6291

6392
### [jr.ptobject] PropTypes.object
6493

6594
```javascript
66-
95+
{
96+
optionalObject: React.PropTypes.object,
97+
requiredObject: React.PropTypes.object.isRequired
98+
}
6799
```
68100

69101
### [jr.ptootype] PropTypes.oneOfType
70102

71103
```javascript
72-
104+
{
105+
optionalUnion: React.PropTypes.oneOfType([
106+
React.PropTypes.bool,
107+
React.PropTypes.string
108+
]),
109+
110+
requiredUnion: React.PropTypes.oneOfType([
111+
React.PropTypes.bool,
112+
React.PropTypes.string
113+
]).isRequired,
114+
}
73115
```
74116

75117
### [jr.ptoneof] PropTypes.oneOf
76118

77119
```javascript
78-
120+
{
121+
optionalEnum: React.PropTypes.oneOf(['Thing 1', 'Thing 2']),
122+
optionalEnum: React.PropTypes.oneOf(['Thing 1', 'Thing 2']).isRequired
123+
}
79124
```
80125

81126
### [jr.ptshape] PropTypes.shape
82127

83128
```javascript
84-
129+
{
130+
optionalObjectWithShape: React.PropTypes.shape({
131+
age: React.PropTypes.number,
132+
name: React.PropTypes.string
133+
}),
134+
135+
requiredObjectWithShape: React.PropTypes.shape({
136+
age: React.PropTypes.number,
137+
name: React.PropTypes.string
138+
}).isRequired,
139+
140+
requiredObjectWithRequiredShape: React.PropTypes.shape({
141+
age: React.PropTypes.number.isRequired,
142+
name: React.PropTypes.string.isRequired
143+
}).isRequired,
144+
}
85145
```
86146

87147
### [jr.ptstring] PropTypes.string
88148

89149
```javascript
90-
150+
{
151+
optionalString: React.PropTypes.string,
152+
requiredString: React.PropTypes.string.isRequired
153+
}
91154
```

snippets/js/libraries/react/spec/README.md

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,41 +3,53 @@
33
### [jr.dname] displayName
44

55
```javascript
6-
6+
displayName: "MyComponent"
77
```
88

99
### [jr.gdprops] getDefaultProps
1010

1111
```javascript
12-
12+
getDefaultProps: function () {
13+
return ${1:\{ key: value \}};
14+
}
1315
```
1416

1517
### [jr.gistate] getInitialState
1618

1719
```javascript
18-
20+
getInitialState: function () {
21+
return ${1:\{ key: value \}};
22+
}
1923
```
2024

2125
### [jr.mixins] mixins
2226

2327
```javascript
24-
28+
mixins: [ AMixinObject, AnotherMixinObject ];
2529
```
2630

2731
### [jr.ptypes] propTypes
2832

2933
```javascript
30-
34+
propTypes: {
35+
myProp: React.PropTypes.bool
36+
}
3137
```
3238

3339
### [jr.srender] render
3440

3541
```javascript
36-
42+
render: function () {
43+
return ${1};
44+
}
3745
```
3846

3947
### [jr.statics] statics
4048

4149
```javascript
42-
50+
statics: {
51+
customMethod: function(foo) {
52+
return foo === 'bar';
53+
}
54+
}
4355
```

0 commit comments

Comments
 (0)