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
Post a Comment