Skip to content

Commit

Permalink
Merge pull request #62 from rhavill/master
Browse files Browse the repository at this point in the history
Fix for Uncaught Invariant Violation #56.
  • Loading branch information
contra committed Sep 15, 2016
2 parents 3ef2983 + 3199bef commit f209447
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 2 deletions.
8 changes: 6 additions & 2 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -96,8 +96,9 @@ var mq = React.createClass({
}
var props = omit(this.props, excludedPropKeys);
var hasMergeProps = Object.keys(props).length > 0;
var childrenCount = React.Children.count(this.props.children);
var wrapChildren = this.props.component ||
React.Children.count(this.props.children) > 1 ||
childrenCount > 1 ||
typeof this.props.children === 'string' ||
this.props.children === undefined;
if (wrapChildren) {
Expand All @@ -111,9 +112,12 @@ var mq = React.createClass({
this.props.children,
props
);
} else {
} else if (childrenCount){
return this.props.children;
}
else {
return null;
}
}
});

Expand Down
11 changes: 11 additions & 0 deletions test/index_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,17 @@ describe('MediaQuery', function() {
);
assert.throws(() => (TestUtils.renderIntoDocument(mq)), 'Invalid or missing MediaQuery!');
});
it('renders nothing when children is an empty array', function() {
const mq = (
<MediaQuery query="all">
{[].map((content, index) => {
return <div key={index}>{content}</div>
})}
</MediaQuery>
);
const e = TestUtils.renderIntoDocument(mq);
assert.equal(e.render(), null);
});
});
it('renders nothing when no matches', function() {
const mq = (
Expand Down

0 comments on commit f209447

Please sign in to comment.