Created
March 14, 2017 09:15
-
-
Save swcho/37104c7065ed1cb728ca57f365f98c46 to your computer and use it in GitHub Desktop.
Dynamic hoc
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
height = -1; | |
leftMenu; | |
registerHeightChange(element: React.ReactElement<{}>) { | |
const Component = element.type['WrappedComponent']; | |
const orig = Component.prototype.componentDidUpdate; | |
const thiz = this; | |
Component.prototype.componentDidUpdate = function() { | |
// console.log(this); | |
const self = ReactDOM.findDOMNode(this); | |
if (thiz.height !== self.clientHeight) { | |
thiz.height = self.clientHeight; | |
console.log('height', thiz.height); | |
if (thiz.leftMenu) { | |
thiz.leftMenu['forceUpdate'](); | |
} | |
} | |
// console.log(thiz); | |
if (orig) { | |
orig.call(this); | |
} | |
}; | |
return element; | |
} | |
render() { | |
return ( | |
… | |
{ this.registerHeightChange(this.props.children) } | |
... | |
) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment