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
fix(browser): Resize Detector is now lazily used in order to prevent #6. Thanks @tonyxiao!
element-resize-detector package looks to be doing some interfacing with the DOM on import. This
caused issues for users where the DOM was not ready yet.
Copy file name to clipboardExpand all lines: README.md
+26-26Lines changed: 26 additions & 26 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -14,9 +14,9 @@
14
14
* Extensive browser support.
15
15
* Supports any Component type, i.e. stateless/class.
16
16
* Works with React 0.14.x and 15.x.x.
17
-
* 7.67KB gzipped standalone, even smaller if bundled into your own project.
17
+
* 7.67KB gzipped standalone, even smaller if bundled into your own project.
18
18
19
-
## Release Notes
19
+
## Release Notes
20
20
21
21
See here: https://github.com/ctrlplusb/react-sizeme/releases
22
22
@@ -30,7 +30,7 @@ It really does work! Look:
30
30
31
31
https://react-sizeme-example-tupkctjbbt.now.sh
32
32
33
-
## Simple Example
33
+
## Simple Example
34
34
35
35
Below is a super simple example highlighting the use of the library. Read the Usage section in its entirety for a full description on configuration and usage.
36
36
@@ -41,7 +41,7 @@ class MyComponent extends Component {
41
41
render() {
42
42
// We receive width and height via "size" prop!
43
43
const { width } =this.props.size;
44
-
44
+
45
45
return (
46
46
<div>My width is {width}px</div>
47
47
);
@@ -70,23 +70,23 @@ You first have to pass the `SizeMe` function a configuration object. The entire
70
70
71
71
```javascript
72
72
constSizeMeHOC=SizeMe({
73
-
// If true, then any changes to your Components rendered width will cause an
74
-
// recalculation of the "size" prop which will then be be passed into
73
+
// If true, then any changes to your Components rendered width will cause an
74
+
// recalculation of the "size" prop which will then be be passed into
75
75
// your Component.
76
-
// If false, then any changes to your Components rendered width will NOT
77
-
// cause any recalculation of the "size" prop. Additionally any "size" prop
78
-
// that is passed into your Component will always have a `null` value
76
+
// If false, then any changes to your Components rendered width will NOT
77
+
// cause any recalculation of the "size" prop. Additionally any "size" prop
78
+
// that is passed into your Component will always have a `null` value
79
79
// for the "width" property.
80
-
monitorWidth:true,
81
-
// If true, then any changes to your Components rendered height will cause an
82
-
// recalculation of the "size" prop which will then be be passed into
80
+
monitorWidth:true,
81
+
// If true, then any changes to your Components rendered height will cause an
82
+
// recalculation of the "size" prop which will then be be passed into
83
83
// your Component.
84
-
// If false, then any changes to your Components rendered height will NOT
85
-
// cause any recalculation of the "size" prop. Additionally any "size" prop
86
-
// that is passed into your Component will always have a `null` value
84
+
// If false, then any changes to your Components rendered height will NOT
85
+
// cause any recalculation of the "size" prop. Additionally any "size" prop
86
+
// that is passed into your Component will always have a `null` value
87
87
// for the "height" property.
88
88
monitorHeight:false,
89
-
// The maximum frequency, in milliseconds, at which size changes should be
89
+
// The maximum frequency, in milliseconds, at which size changes should be
90
90
// recalculated when changes in your Component's rendered size are being
91
91
// detected. This should not be set to lower than 16.
92
92
refreshRate:16
@@ -97,15 +97,15 @@ __IMPORTANT__: We don't monitor height by default, so if you use the default set
97
97
98
98
__IMPORTANT__: If you aren't monitoring a specific dimension (width or height) you will be provided `null` values for the respective dimension. This is to avoid any possible misconfigured implementation whoopsies.
99
99
100
-
__IMPORTANT__: `refreshRate` is set very low. If you are using this library in a manner where you expect loads of active changes to your components dimensions you may need to tweak this value to avoid browser spamming.
100
+
__IMPORTANT__: `refreshRate` is set very low. If you are using this library in a manner where you expect loads of active changes to your components dimensions you may need to tweak this value to avoid browser spamming.
101
101
102
102
When you execute the `SizeMe` function it will return a Higher Order Component. You can use this Higher Order Component to decorate any of your existing Components with the size awareness ability. Each of the Components you decorate will then recieve a `size` prop, which is an object of schema `{ width: number, height: number }` - the numbers representing pixel values. Below is an example:
103
103
104
104
```javascript
105
105
classMyComponentextendsComponent {
106
106
render() {
107
107
const { width, height } =this.props.size;
108
-
108
+
109
109
return (
110
110
<div>My size is {width}px x {height}px</div>
111
111
);
@@ -126,9 +126,9 @@ import SmallChildComponent from './SmallChildComponent';
126
126
importSizeMefrom'react-sizeme';
127
127
128
128
functionMyComponent(props) {
129
-
const { width, height } =props.size;
129
+
const { width, height } =props.size;
130
130
131
-
constToRenderChild= height >600
131
+
constToRenderChild= height >600
132
132
? LargeChildComponent
133
133
: SmallChildComponent;
134
134
@@ -167,8 +167,8 @@ const inlineStyle = {
167
167
168
168
functionApp() {
169
169
return (
170
-
<MySizeAwareComponent
171
-
className={cssStyles.foo}
170
+
<MySizeAwareComponent
171
+
className={cssStyles.foo}
172
172
style={inlineStyle} />
173
173
);
174
174
}
@@ -185,7 +185,7 @@ class MyComponent extends Component {
185
185
render() {
186
186
constclassName=this.props.className;
187
187
const { width, height } =this.props.size;
188
-
188
+
189
189
return (
190
190
<div className={className}>
191
191
My size is {width}px x {height}px
@@ -215,9 +215,9 @@ If however you wish to use this library to wrap a component that you expect to b
215
215
216
216
## Caveats.
217
217
218
-
* Server Side Rendering is not supported. I am still thinking of the best approach on what to do in the case of a SSR request. Perhaps I will just return null values for width/height. Undecided. Any recommendations are welcome.
219
-
* Whilst execution is performant and we try and do smart rendering mechanisms we don't recommend that you place a crazy amount of size aware components into your render tree. If you do require this I highly recommend you do some decent browser testing for impact.
218
+
* Server Side Rendering is not supported (yet). Keep track of this in issue #7.
219
+
* Whilst execution is performant and we try and do smart rendering mechanisms we don't recommend that you place a crazy amount of size aware components into your render tree. If you do require this I highly recommend you do some decent browser testing for impact.
220
220
221
221
## Extreme Appreciation!
222
222
223
-
We make use of the awesome [element-resize-detector](https://github.com/wnr/element-resize-detector) library. This library makes use of an scroll/object based event strategy which outperforms window resize event listening dramatically. The original idea for this approach comes from another library, namely [css-element-queries](https://github.com/marcj/css-element-queries) by Marc J. Schmidt. I recommend looking into these libraries for history, specifics, and more examples. I love them for the work they did, whithout which this library would not be possible. :sparkle-heart:
223
+
We make use of the awesome [element-resize-detector](https://github.com/wnr/element-resize-detector) library. This library makes use of an scroll/object based event strategy which outperforms window resize event listening dramatically. The original idea for this approach comes from another library, namely [css-element-queries](https://github.com/marcj/css-element-queries) by Marc J. Schmidt. I recommend looking into these libraries for history, specifics, and more examples. I love them for the work they did, whithout which this library would not be possible. :sparkle-heart:
0 commit comments