Skip to content

Commit

Permalink
Fix for Uncaught Invariant Violation #56. Return null from render fun…
Browse files Browse the repository at this point in the history
…ction when MediaQuery has no children.
  • Loading branch information
Ricardo Havill committed Sep 14, 2016
1 parent 3ef2983 commit fdb34e8
Showing 1 changed file with 6 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

0 comments on commit fdb34e8

Please sign in to comment.