Skip to content
This repository was archived by the owner on Sep 23, 2025. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,8 @@ or as an [ES7 class decorator](https://github.com/wycats/javascript-decorators)
- `options.className` **[string](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String)=** Control the class name set on the wrapper `<div>`
- `options.elementResize` **[boolean](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Boolean)=** Set true to watch the wrapper `div` for changes in
size which are not a result of window resizing - e.g. changes to the flexbox and other layout. (optional, default `false`)
- `options.withRef` **[boolean](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Boolean)=** Set true to enable accessing the wrapped instance with
[getWrappedInstance()](https://github.com/digidem/react-dimensions#getwrappedinstance). Disable this when wrapping stateless components, as they cannot use `refs`. (optional, default `true`)

**Examples**

Expand Down
2 changes: 1 addition & 1 deletion example.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ class MyComponent extends React.Component {
}}>
{`${this.props.containerWidth}px x ${this.props.containerHeight}px`}
</div>
)
)
}
}

Expand Down
8 changes: 6 additions & 2 deletions index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,8 @@ module.exports = function Dimensions ({
getDimensions = defaultGetDimensions,
debounce = 0,
debounceOpts = {},
elementResize = false
elementResize = false,
withRef = true
} = {}) {
return (ComposedComponent) => {
return class DimensionsHOC extends React.Component {
Expand Down Expand Up @@ -152,6 +153,9 @@ module.exports = function Dimensions ({
* @return {object} The rendered React component
**/
getWrappedInstance () {
if (!withRef) {
console.warn('You need to enable the `withRef` option to access the wrapped instance')
}
return this.refs.wrappedInstance
}

Expand All @@ -173,7 +177,7 @@ module.exports = function Dimensions ({
{...this.state}
{...this.props}
updateDimensions={this.updateDimensions}
ref='wrappedInstance'
ref={withRef && 'wrappedInstance'}
/>
}
</div>
Expand Down