You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+3-5
Original file line number
Diff line number
Diff line change
@@ -1,13 +1,12 @@
1
1
# react-media-query-hoc
2
-
A dead simple React Higher Order Component (HOC) that uses context for matching media queries
2
+
A dead simple React Higher Order Component (HOC) that uses context for matching media queries.
3
3
4
4
5
5
## Why use this?
6
6
- A simple API which doesnt require you to put `MediaQuery` components all over your code base
7
7
- More performant (you only need 1 parent `MediaQueryProvider` that listens to media events you wish to configure)
8
8
- Easier to test than other react media query libraries
9
-
- Uses [matchmedia](https://github.com/iceddev/matchmedia) for media queries for client and server
10
-
- Abstracted away React context which is experimental (and subject to change for <= React 15)
9
+
- Uses [css-mediaquery](https://github.com/ericf/css-mediaquery) for server side rendering
11
10
12
11
## Why not use this?
13
12
We always recommend using vanilla CSS media queries to build responsive websites, this is simpler and provides a smoother UX, also it mitigates having to guess the screen width during [server side rendering](#server-side-rendering). At Domain we needed to use this component for legacy ad tech and advise against it's use for general responsive website design.
@@ -31,7 +30,7 @@ This library is designed so that you have 1 `MediaQueryProvider` parent and 1-ma
31
30
32
31
### `MediaQueryProvider`
33
32
34
-
This component will listen to media events you want to configure, it should be used once as a parent component
33
+
This component will listen to media events you want to configure, it should be used once as a parent component.
35
34
36
35
**Usage:**
37
36
@@ -71,7 +70,6 @@ const App = (props) => {
71
70
### `withMedia`
72
71
73
72
This is a HOC to provide media match props to your component.
74
-
This abstracts away context so that if there is any changes to the API in the future its easier to upgrade (see: [React Context](https://facebook.github.io/react/docs/context.html))
function_classCallCheck(instance,Constructor){if(!(instanceinstanceofConstructor)){thrownewTypeError("Cannot call a class as a function");}}
28
32
29
33
function_possibleConstructorReturn(self,call){if(!self){thrownewReferenceError("this hasn't been initialised - super() hasn't been called");}returncall&&(typeofcall==="object"||typeofcall==="function") ? call : self;}
30
34
31
35
function_inherits(subClass,superClass){if(typeofsuperClass!=="function"&&superClass!==null){thrownewTypeError("Super expression must either be null or a function, not "+typeofsuperClass);}subClass.prototype=Object.create(superClass&&superClass.prototype,{constructor: {value: subClass,enumerable: false,writable: true,configurable: true}});if(superClass)Object.setPrototypeOf ? Object.setPrototypeOf(subClass,superClass) : subClass.__proto__=superClass;}
32
36
33
-
vardefaultQueries={
34
-
mobile: 'screen and (max-width: 623px)',
35
-
tablet: 'screen and (min-width: 624px) and (max-width: 1020px)',
36
-
desktop: 'screen and (min-width: 1021px) and (max-width: 1440px)',
37
-
largeDesktop: 'screen and (min-width: 1441px)'
38
-
};
37
+
varisServer=typeofprocess!=='undefined';
39
38
40
39
varMediaQueryProvider=function(_React$Component){
41
40
_inherits(MediaQueryProvider,_React$Component);
@@ -45,28 +44,49 @@ var MediaQueryProvider = function (_React$Component) {
0 commit comments