You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Simplified NestedTypes-style type annotations can be used as props spec:
207
+
- constructor functions: `Type`
208
+
- constructors with default values: `Type.value( x )`
209
+
- JSON and primitive values: `"default string"`
210
+
211
+
No other type annotation features are supported for `props`.
212
+
213
+
When component has `props` type spec:
214
+
- React component propTypes will be automatically generated for every props;
215
+
- if props has explicitly defined default value, getDefaultProps() method will be created. It means, that there are *no*
216
+
default objects generated for simple `Type` style type spec.
217
+
180
218
## Pure Render Mixin
181
219
182
220
```javscript
183
221
var MyComponent = React.createClass({
184
-
propTypes : {
185
-
item : PropTypes.instanceOf( MyModel ),
186
-
elements : PropTypes.instanceOf( MyCollection ),
187
-
className : PropTypes.string
222
+
props : {
223
+
item : MyModel,
224
+
elements : MyCollection,
225
+
className : String
188
226
},
189
227
190
228
pureRender : true,
@@ -198,9 +236,9 @@ var MyComponent = React.createClass({
198
236
```
199
237
200
238
PureRender optimization in enabled with `pureRender` option. It will create `shouldComponentUpdate` function
201
-
which is optimized for props mentioned in `propTypes`.
239
+
which is optimized for props mentioned in `propTypes` or `props` declaration.
202
240
203
-
Therefore, it's required to declare all of component props in `propTypes`when using this optimization.
241
+
Therefore, it's required to declare all of component props when using this optimization.
204
242
205
243
## Data binding
206
244
@@ -282,7 +320,7 @@ For link enclosings arrays and plain JS objects:
282
320
283
321
Link received through component props can be mapped as state member using the following declaration:
284
322
```javascript
285
-
attributes: {
323
+
state: {
286
324
selected :Nested.link( '^props.selectedLink' )
287
325
}
288
326
```
@@ -291,7 +329,7 @@ It can be accessed as a part of state, however, in this case it's not true state
291
329
Also, links can be used to declaratively expose real component state to upper conponents. In this example, link optionally received in props will be updated every time `this.state.selected` object is replaced. In this case, updates are one way, from bottom component to upper one, and stateful component will render itself when state is changed.
0 commit comments