- If you have some unwanted properties in your
props
, do not drop all of them using{...props}
to the child component. Pass the props that are needed by the component. (facebook/react#7157 (comment))
// BAD (if there are unwanted props)
render() {
return (
<Foo {...this.props} />
);
}
// GOOD
render() {
var { unwantedProps, ...neededProps } = this.props;
return (
<Foo {...neededProps} />
);
}
- Don’t apply inheritance to React components. Composition is simpler and works better (https://twitter.com/dan_abramov/status/752643494972383232)
var PurpleComponent = React.createClass({
render: function() {
return <FirstComponent {...this.props} color="purple" />;
},
});