Helpers to manage browser size changes in React.
Two Higher-Order Components are provided:
Listens to an element's own size changes through element-resize-detector.
Component: the component to wrapuseCallback: by default, the HOC augments properties with adimensionsprop containing{width,height}. If you prefer to manage state internally, then you can provide anonResizecallback in your component.useScroll: use thescrollstrategy (see element-resize-detector).propName: ifuseCallbackisfalse, sets the name of the prop that receives the dimensions (by default,dimensions). IfuseCallbackistrue, sets the name of the callback (by default,onResize)
Listens to window resize events through jobj
Component: the component to wrapuseCallback: by default, the HOC augments properties with adimensionsprop containing{vw,vh,dw,dh}(corresponding respectively towindowanddocumentdimensions). If you prefer to manage state internally, then you can provide anonResizecallback in your component.propName: ifuseCallbackisfalse, sets the name of the prop that receives the dimensions (by default,dimensions). IfuseCallbackistrue, sets the name of the callback (by default,onResize)
npm install react-sizeimport 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')MIT