package
Create React components that favor pure render functions and immutable props.
npm install pure-componentGitHub-flavored package documentation.
Across all versions, last 30 days.
36 in 30 days
Runtime metadata.
Estimated unpacked size across 4 packages.
1.5 MB
Includes dependencies.
3 direct · 2 outdated
Create React components that favor pure render functions and immutable props.
Using a pure render function:
var React = require('react');
var ReactDom = require('react-dom');
var pureComponent = require('pure-component');
var myComponent = pureComponent(function myComponentRender(props) {
return React.DOM.p(null, props.text);
});
ReactDom.render(myComponent({text: 'Hello'}), document.body);Using a spec object:
var React = require('react');
var ReactDom = require('react-dom');
var pureComponent = require('pure-component');
var myComponentSpec = {
displayName: 'My Component',
contextTypes: {
greeting: React.PropTypes.string
},
render: function (props, context) {
return React.DOM.p(null, context.greeting + ' ' + props.children);
}
};
var myComponent = pureComponent(myComponentSpec);
var myAppSpec =
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.
The component display name is taken either from the spec, or the displayName or name of the render function, in that order.