@@ -27,7 +27,7 @@ But it's not limited to this case. Just use that at your needs.
2727#### With class component.
2828``` jsx
2929import React , { Component } from ' react' ;
30- import Sizes from ' react-sizes' ;
30+ import withSizes from ' react-sizes' ;
3131
3232class MyComponent extends Component {
3333 render () {
@@ -41,16 +41,16 @@ const mapSizesToProps = ({ width }) => ({
4141 isMobile: width < 480 ,
4242});
4343
44- export Sizes (mapSizesToProps )(MyComponent );
44+ export default withSizes (mapSizesToProps)(MyComponent);
4545```
4646You can play with this example [ here] ( https://codesandbox.io/s/Rg0DDOWnE ) .
4747
4848#### As decorator.
4949``` jsx
5050import React from ' react' ;
51- import Sizes from ' react-sizes' ;
51+ import withSizes from ' react-sizes' ;
5252
53- @Sizes (({ width }) => ({ isMobile: width < 480 }))
53+ @withSizes (({ width }) => ({ isMobile: width < 480 }))
5454class MyComponent extends Component {
5555 render () {
5656 return (
@@ -62,10 +62,33 @@ class MyComponent extends Component {
6262export default MyComponent ;
6363```
6464
65+ #### Interoperate with other libraries.
66+ ``` jsx
67+ import React from ' react' ;
68+ import withSizes from ' react-sizes' ;
69+ import { withState , compose } from ' recompose' ;
70+
71+ const enhancer = compose (
72+ withState (' counter' , ' setCounter' , 0 ),
73+ withSizes (({ width }) => ({ isMobile: width < 480 })),
74+ );
75+
76+ const MyComponent = enhancer (({ isMobile, counter, setCounter }) => (
77+ < div>
78+ < div>
79+ Count: {counter} < button onClick= {() => setCounter (n => n + 1 )}> Increment< / button>
80+ < / div>
81+ < div> {isMobile ? ' Is Mobile' : ' Is Not Mobile' }< / div>
82+ < / div>
83+ ));
84+
85+ export default MyComponent ;
86+ ```
87+
6588#### With functional component.
6689``` jsx
6790import React from ' react' ;
68- import Sizes from ' react-sizes' ;
91+ import withSizes from ' react-sizes' ;
6992
7093const MyComponent = ({ isMobile }) => (
7194 < div> {isMobile ? ' Is Mobile' : ' Is Not Mobile' }< / div>
@@ -75,30 +98,30 @@ const mapSizesToProps = ({ width }) => ({
7598 isMobile: width < 480 ,
7699});
77100
78- export Sizes (mapSizesToProps )(MyComponent );
101+ export default withSizes (mapSizesToProps)(MyComponent);
79102```
80103
81- #### Interoperate with other libraries.
104+ #### Mess with props.
105+ (Added in 0.1.0)
82106``` jsx
83107import React from ' react' ;
84- import Sizes from ' react-sizes' ;
85- import { withState , compose } from ' recompose' ;
108+ import withSizes from ' react-sizes' ;
86109
87- const enhancer = compose (
88- withState (' counter' , ' setCounter' , 0 ),
89- Sizes (({ width }) => ({ isMobile: width < 480 })),
110+ const MyComponent = ({ isMobile }) => (
111+ < div> {isMobile ? ' Is Mobile' : ' Is Not Mobile' }< / div>
90112);
91113
92- const MyComponent = enhancer (({ isMobile, counter, setCounter }) => (
93- < div>
94- < div>
95- Count: {counter} < button onClick= {() => setCounter (n => n + 1 )}> Increment< / button>
96- < / div>
97- < div> {isMobile ? ' Is Mobile' : ' Is Not Mobile' }< / div>
98- < / div>
99- ));
114+ const mapSizesToProps = ({ width }, { mobileBreakpoint }) => ({
115+ isMobile: width < mobileBreakpoint,
116+ });
100117
101- export default MyComponent ;
118+ export default withSizes (mapSizesToProps)(MyComponent);
119+ ```
120+ then:
121+ ``` jsx
122+ < MyComponent mobileBreakpoint= {480 } / >
123+ < MyComponent mobileBreakpoint= {400 } / >
124+ < MyComponent mobileBreakpoint= {600 } / >
102125```
103126
104127#### With presets selectors.
@@ -108,26 +131,26 @@ export default MyComponent;
108131- });
109132
110133+ const mapSizesToProps = sizes => ({
111- + isMobile: Sizes .isMobile(sizes),
134+ + isMobile: withSizes .isMobile(sizes),
112135+ });
113136```
114137
115138## Presets Selectors
116139
117- You can check all ** our** presets selectors at our main code ` src/Sizes .js ` .
140+ You can check all ** our** presets selectors at our main code ` src/withSizes .js ` .
118141``` js
119- Sizes .isMobile = ({ width }) => width < 480 ;
120- Sizes .isTablet = ({ width }) => width >= 480 && width < 1024 ;
121- Sizes .isDesktop = ({ width }) => width >= 1024 ;
142+ withSizes .isMobile = ({ width }) => width < 480 ;
143+ withSizes .isTablet = ({ width }) => width >= 480 && width < 1024 ;
144+ withSizes .isDesktop = ({ width }) => width >= 1024 ;
122145
123- Sizes .isGtMobile = (sizes ) => ! Sizes .isMobile (sizes);
124- Sizes .isGtTablet = (sizes ) => Sizes .isDesktop (sizes);
146+ withSizes .isGtMobile = (sizes ) => ! withSizes .isMobile (sizes);
147+ withSizes .isGtTablet = (sizes ) => withSizes .isDesktop (sizes);
125148
126- Sizes .isStTablet = (sizes ) => Sizes .isMobile (sizes);
127- Sizes .isStDesktop = (sizes ) => ! Sizes .isStDesktop (sizes);
149+ withSizes .isStTablet = (sizes ) => withSizes .isMobile (sizes);
150+ withSizes .isStDesktop = (sizes ) => ! withSizes .isStDesktop (sizes);
128151
129- Sizes .isTabletAndGreater = (sizes ) => ! Sizes .isMobile (sizes);
130- Sizes .isTabletAndSmaller = (sizes ) => ! Sizes .isStDesktop (sizes);
152+ withSizes .isTabletAndGreater = (sizes ) => ! withSizes .isMobile (sizes);
153+ withSizes .isTabletAndSmaller = (sizes ) => ! withSizes .isStDesktop (sizes);
131154```
132155
133156If it don't fit to your needs, you can create your own selectors.
0 commit comments