From fdb34e8d830bc6d405b07afceca1dfb117808591 Mon Sep 17 00:00:00 2001 From: Ricardo Havill Date: Wed, 14 Sep 2016 19:41:06 -0400 Subject: [PATCH] Fix for Uncaught Invariant Violation #56. Return null from render function when MediaQuery has no children. --- src/index.js | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/index.js b/src/index.js index ed528b5..fb538a9 100644 --- a/src/index.js +++ b/src/index.js @@ -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) { @@ -111,9 +112,12 @@ var mq = React.createClass({ this.props.children, props ); - } else { + } else if (childrenCount){ return this.props.children; } + else { + return null; + } } });