Skip to content

Commit 1143011

Browse files
author
Matt Zabriskie
committed
Using React.Children.only
1 parent cfa99ba commit 1143011

File tree

1 file changed

+6
-20
lines changed

1 file changed

+6
-20
lines changed

lib/draggable.js

Lines changed: 6 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -246,13 +246,6 @@ module.exports = React.createClass({
246246
};
247247
},
248248

249-
componentWillMount: function () {
250-
invariant(
251-
React.Children.count(this.props.children) === 1,
252-
'There should only be a single child element within Draggable.'
253-
);
254-
},
255-
256249
handleMouseDown: function (e) {
257250
var node = this.getDOMNode();
258251

@@ -324,18 +317,11 @@ module.exports = React.createClass({
324317

325318
// Reuse the child provided
326319
// This makes it flexible to use whatever element is wanted (div, ul, etc)
327-
var child = null;
328-
React.Children.forEach(this.props.children, function (c) {
329-
if (child === null) {
330-
child = React.addons.cloneWithProps(c, {
331-
style: style,
332-
className: 'react-draggable',
333-
onMouseUp: this.handleMouseUp,
334-
onMouseDown: this.handleMouseDown
335-
});
336-
}
337-
}, this);
338-
339-
return child;
320+
return React.addons.cloneWithProps(React.Children.only(this.props.children), {
321+
style: style,
322+
className: 'react-draggable',
323+
onMouseUp: this.handleMouseUp,
324+
onMouseDown: this.handleMouseDown
325+
});
340326
}
341327
});

0 commit comments

Comments
 (0)