Skip to content

Commit

Permalink
Do not require a component to wrap MediaQuery children
Browse files Browse the repository at this point in the history
- If a props.component was not explicitly defined and there is only 1
  child inside the MediaQuery, just render the child instead of wrapping
  it in a div.
  • Loading branch information
jdlehman committed Nov 5, 2015
1 parent 62af1d5 commit 4543f17
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ var mq = React.createClass({

getDefaultProps: function(){
return {
component: 'div',
values: {}
};
},
Expand Down Expand Up @@ -87,7 +86,15 @@ var mq = React.createClass({
return null;
}
var props = omit(this.props, excludedPropKeys);
return React.createElement(this.props.component, props, this.props.children);
if (this.props.component || this.props.children.length > 1) {
return React.createElement(
this.props.component || 'div',
props,
this.props.children
);
} else {
return this.props.children;
}
}
});

Expand Down

0 comments on commit 4543f17

Please sign in to comment.