Skip to content

Commit 32b64ba

Browse files
committed
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.
1 parent 542959d commit 32b64ba

File tree

2 files changed

+29
-29
lines changed

2 files changed

+29
-29
lines changed

README.md

Lines changed: 26 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,9 @@
1414
* Extensive browser support.
1515
* Supports any Component type, i.e. stateless/class.
1616
* 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.
1818

19-
## Release Notes
19+
## Release Notes
2020

2121
See here: https://github.com/ctrlplusb/react-sizeme/releases
2222

@@ -30,7 +30,7 @@ It really does work! Look:
3030

3131
https://react-sizeme-example-tupkctjbbt.now.sh
3232

33-
## Simple Example
33+
## Simple Example
3434

3535
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.
3636

@@ -41,7 +41,7 @@ class MyComponent extends Component {
4141
render() {
4242
// We receive width and height via "size" prop!
4343
const { width } = this.props.size;
44-
44+
4545
return (
4646
<div>My width is {width}px</div>
4747
);
@@ -70,23 +70,23 @@ You first have to pass the `SizeMe` function a configuration object. The entire
7070

7171
```javascript
7272
const SizeMeHOC = 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
7575
// 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
7979
// 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
8383
// 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
8787
// for the "height" property.
8888
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
9090
// recalculated when changes in your Component's rendered size are being
9191
// detected. This should not be set to lower than 16.
9292
refreshRate: 16
@@ -97,15 +97,15 @@ __IMPORTANT__: We don't monitor height by default, so if you use the default set
9797

9898
__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.
9999

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.
101101

102102
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:
103103

104104
```javascript
105105
class MyComponent extends Component {
106106
render() {
107107
const { width, height } = this.props.size;
108-
108+
109109
return (
110110
<div>My size is {width}px x {height}px</div>
111111
);
@@ -126,9 +126,9 @@ import SmallChildComponent from './SmallChildComponent';
126126
import SizeMe from 'react-sizeme';
127127

128128
function MyComponent(props) {
129-
const { width, height } = props.size;
129+
const { width, height } = props.size;
130130

131-
const ToRenderChild = height > 600
131+
const ToRenderChild = height > 600
132132
? LargeChildComponent
133133
: SmallChildComponent;
134134

@@ -167,8 +167,8 @@ const inlineStyle = {
167167

168168
function App() {
169169
return (
170-
<MySizeAwareComponent
171-
className={cssStyles.foo}
170+
<MySizeAwareComponent
171+
className={cssStyles.foo}
172172
style={inlineStyle} />
173173
);
174174
}
@@ -185,7 +185,7 @@ class MyComponent extends Component {
185185
render() {
186186
const className = this.props.className;
187187
const { width, height } = this.props.size;
188-
188+
189189
return (
190190
<div className={className}>
191191
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
215215

216216
## Caveats.
217217

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.
220220

221221
## Extreme Appreciation!
222222

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:

package.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -77,12 +77,12 @@
7777
"react": "^0.14.0 || ^15.0.0",
7878
"react-dom": "^0.14.0 || ^15.0.0"
7979
},
80-
"czConfig": {
81-
"path": "node_modules/cz-conventional-changelog"
82-
},
8380
"config": {
8481
"ghooks": {
8582
"pre-commit": "npm run test"
83+
},
84+
"commitizen": {
85+
"path": "node_modules/cz-conventional-changelog"
8686
}
8787
},
8888
"dependencies": {

0 commit comments

Comments
 (0)