nkbt / react-height

Component-wrapper to determine and report children elements height
MIT License
180 stars 27 forks source link

Error with Hidden prop #31

Closed Themandunord closed 7 years ago

Themandunord commented 7 years ago

Hi,

When I use the hidden prop, I have an error in the console :

bundle.min.js:206314 Uncaught TypeError: Cannot read property 'clientHeight' of null
    at Object.getElementHeight (bundle.min.js:206314)
    at ReactHeight.componentDidUpdate (bundle.min.js:206363)
    at measureLifeCyclePerf (bundle.min.js:56076)
    at bundle.min.js:56730
    at CallbackQueue.notifyAll (bundle.min.js:48644)
    at ReactReconcileTransaction.close (bundle.min.js:59436)
    at ReactReconcileTransaction.closeAll (bundle.min.js:49827)
    at ReactReconcileTransaction.perform (bundle.min.js:49774)
    at ReactUpdatesFlushTransaction.perform (bundle.min.js:49761)
    at ReactUpdatesFlushTransaction.perform (bundle.min.js:48401)

The content is null with this prop, but why I have the error ?

Thanks.

nkbt commented 7 years ago

Should work fine, no idea. Can you give a codepen with the error you have?

Themandunord commented 7 years ago

Just an update,

I don't have time to make a codepen actually. But I fine a workaround that work.

In the parent of the ReactHeight (so my component), I redefine the getElementHeight function :

<ReactHeight 
    hidden={true}
    getElementHeight={this.__getElementHeight}
    onHeightReady={height => this.setState({clientHeight: height})}>
    {this.props.children}
</ReactHeight>
__getElementHeight(el){
        if(el) {
            return this.clientHeight = el.clientHeight;
        }
        return this.clientHeight;
    },

this.clientHeight it's a variable of my class.

It's weird but it's works...

Otherwise, thank you for this component ;)

nkbt commented 7 years ago

Cheers!