Make sure cloneElement() supports prototype-less config (#6878)

This brings createElement() fix from #6855 to cloneElement().
This commit is contained in:
Dan Abramov
2016-05-26 00:37:18 +01:00
parent a0ff2e77de
commit d31e259a83
2 changed files with 6 additions and 1 deletions
@@ -311,7 +311,7 @@ ReactElement.cloneElement = function(element, config, children) {
defaultProps = element.type.defaultProps;
}
for (propName in config) {
if (config.hasOwnProperty(propName) &&
if (hasOwnProperty.call(config, propName) &&
!RESERVED_PROPS.hasOwnProperty(propName)) {
if (config[propName] === undefined && defaultProps !== undefined) {
// Resolve default props
@@ -78,6 +78,11 @@ describe('ReactElementClone', function() {
);
});
it('does not fail if config has no prototype', function() {
var config = Object.create(null, {foo: {value: 1, enumerable: true}});
React.cloneElement(<div />, config);
});
it('should keep the original ref if it is not overridden', function() {
var Grandparent = React.createClass({
render: function() {