Pure Component
Create React components that favor pure render functions and immutable props.
Usage
Using a pure render function:
var React = ;var ReactDom = ;var pureComponent = ; var myComponent = ; ReactDom;
Using a spec object:
var React = ;var ReactDom = ;var pureComponent = ; var myComponentSpec = displayName: 'My Component' contextTypes: greeting: ReactPropTypesstring { return ReactDOM; }; var myComponent = ; var myAppSpec = childContextTypes: greeting: ReactPropTypesstring { return greeting: 'Hello'; } { return ; }; var myApp = ; React;
Spec
When passing in a spec object all of it’s own properties other than contextTypes
, defaultProps
, displayName
and propTypes
are added to the created component’s prototype. The mentioned props get added directly on the constructor instead.
Unless overwritten from spec, components default to using the pure render shouldComponentUpdate
.
The render function receives props
and an optional context
as arguments.
Display name
The component display name is taken either from the spec, or the displayName
or name
of the render function, in that order.