javascript - How does @withViewPort decorator work in React? -


i reading decorators , fount @withviewport usage :

import react 'react'; import withviewport 'react-decorators/withviewport';  @withviewport class mycomponent {   render() {     let { width, height } = this.props.viewport;     return <div>viewport: {width + 'x' + height}</div>;   } }  react.render(<mycomponent />, document.body); 

how work @withviewport decorator work? have state , these state changes while resizing window size?

it's higher order component adds handler listening window.resize component. src: https://github.com/kriasoft/react-decorators/blob/master/src/withviewport.js

the decorator same doing:

const mycomposedcomponent = withcomponent(mycomponent); render(<mycomposedcomponent />, document.body); 

Comments

Popular posts from this blog

PySide and Qt Properties: Connecting signals from Python to QML -

c# - DevExpress.Wpf.Grid.InfiniteGridSizeException was unhandled -

scala - 'wrong top statement declaration' when using slick in IntelliJ -