File tree Expand file tree Collapse file tree 1 file changed +18
-7
lines changed Expand file tree Collapse file tree 1 file changed +18
-7
lines changed Original file line number Diff line number Diff line change 11import React , { PropTypes } from 'react'
22import json2mq from 'json2mq'
33
4+ /**
5+ * Conditionally renders based on whether or not a media query matches.
6+ */
47class Media extends React . Component {
58 static propTypes = {
69 query : PropTypes . oneOfType ( [
@@ -43,13 +46,21 @@ class Media extends React.Component {
4346 const { children, render } = this . props
4447 const { matches } = this . state
4548
46- if ( matches && render )
47- return render ( )
48-
49- if ( typeof children === 'function' )
50- return children ( matches )
51-
52- return matches ? React . Children . only ( children ) : null
49+ return (
50+ render ? (
51+ matches ? render ( ) : null
52+ ) : children ? (
53+ typeof children === 'function' ? (
54+ children ( matches )
55+ ) : ! Array . isArray ( children ) || children . length ? ( // Preact defaults to empty children array
56+ matches ? React . Children . only ( children ) : null
57+ ) : (
58+ null
59+ )
60+ ) : (
61+ null
62+ )
63+ )
5364 }
5465}
5566
You can’t perform that action at this time.
0 commit comments