File tree Expand file tree Collapse file tree 3 files changed +9
-8
lines changed Expand file tree Collapse file tree 3 files changed +9
-8
lines changed Original file line number Diff line number Diff line change 11import React from "react" ;
22import PropTypes from "prop-types" ;
3+ import invariant from "invariant" ;
34import json2mq from "json2mq" ;
45
56/**
@@ -31,15 +32,14 @@ class Media extends React.Component {
3132 componentWillMount ( ) {
3233 if ( typeof window !== "object" ) return ;
3334
34- let { query } = this . props ;
3535 const targetWindow = this . props . targetWindow || window ;
3636
37- if ( ! targetWindow . matchMedia ) {
38- throw new Error (
39- 'You passed a `targetWindow` prop to `Media` that does not have a `matchMedia` function.'
40- ) ;
41- }
37+ invariant (
38+ typeof targetWindow . matchMedia === "function" ,
39+ "<Media targetWindow> does not support `matchMedia`."
40+ ) ;
4241
42+ let { query } = this . props ;
4343 if ( typeof query !== "string" ) query = json2mq ( query ) ;
4444
4545 this . mediaQueryList = targetWindow . matchMedia ( query ) ;
Original file line number Diff line number Diff line change @@ -155,9 +155,9 @@ describe("A <Media>", () => {
155155
156156 expect ( ( ) => {
157157 ReactDOM . render ( element , node , ( ) => { } ) ;
158- } ) . toThrow ( "does not have a `matchMedia` function " ) ;
158+ } ) . toThrow ( "does not support `matchMedia`" ) ;
159159 } ) ;
160- } )
160+ } ) ;
161161 } ) ;
162162
163163 describe ( "rendered on the server" , ( ) => {
Original file line number Diff line number Diff line change 2424 "react" : " >=15 || ^0.14.7"
2525 },
2626 "dependencies" : {
27+ "invariant" : " ^2.2.2" ,
2728 "json2mq" : " ^0.2.0" ,
2829 "prop-types" : " ^15.5.10"
2930 },
You can’t perform that action at this time.
0 commit comments