javascript - Change elements height React Angular -
i'm working angular , react (with ng-react) , i'm trying change height of 1 element match height of element. have react component both of elements inside, this:
render: function() { return ( <div> <div classname="absolute" ref="absolutecell">foo</div> <th ref="emptycell" style={this.state.style}></th> </div> ) }
so want set height of empty cell match 1 of absolute cell. i've tried componentdidmount
this:
getinitialstate: function() { return { style: { height: '30px' } } }, componentdidmount: function() { var absolutecellheight = this.refs.absolutecell.getdomnode().offsetheight; this.setstate({ style: { height: absolutecellheight } }); this.refs.emptycell.forceupdate(); }
but keep getting nasty error cannot read property 'getdomnode' of undefined
. there other way can achieve want?
update: i've changed code (updated above) , error cannot read property 'getdomnode' of undefined
gone i'm getting error typeerror: undefined not function
on line this.refs.emptycell.forceupdate()
.
the height of emptycell changes correctly , works fine, i'm still getting error on foreupdate()
method. have idea? maybe other way want?
the code above react anti-pattern:
in componentdidmount lifecycle, measure height correct, usage of setstate() && forceupdate() should not called in life cycle. setstate calculate difference , re-render react component. forceupdate() duplicate after setstate()
to achieve goal, please move logic of changing style of emptycell componentdidupdate lifecycle, gives opportunity update rendered dom.
Comments
Post a Comment