react-size
v0.1.1
Published
Helpers to manage browser size changes in React.
Downloads
49
Readme
React-size
Helpers to manage browser size changes in React.
Two Higher-Order Components are provided:
listenResize(Component,useCallback,useScroll,propName)
Listens to an element's own size changes through element-resize-detector.
Component
: the component to wrapuseCallback
: by default, the HOC augments properties with adimensions
prop containing{width,height}
. If you prefer to manage state internally, then you can provide anonResize
callback in your component.useScroll
: use thescroll
strategy (see element-resize-detector).propName
: ifuseCallback
isfalse
, sets the name of the prop that receives the dimensions (by default,dimensions
). IfuseCallback
istrue
, sets the name of the callback (by default,onResize
)
listenWindowResize(component,useCallback,propName)
Listens to window resize events through jobj
Component
: the component to wrapuseCallback
: by default, the HOC augments properties with adimensions
prop containing{vw,vh,dw,dh}
(corresponding respectively towindow
anddocument
dimensions). If you prefer to manage state internally, then you can provide anonResize
callback in your component.propName
: ifuseCallback
isfalse
, sets the name of the prop that receives the dimensions (by default,dimensions
). IfuseCallback
istrue
, sets the name of the callback (by default,onResize
)
Usage
npm install react-size
import React from 'react'
import {listenWindowResize} from 'react-size'
class MyComponent extends React.Component{
render(){
return (<div>{this.props.dim.width}</div>)
}
}
export default listenWindowResize(MyComponent,false,'dim')
License
MIT