nkbt / react-collapse

Component-wrapper for collapse animation with react-motion for elements with variable (and dynamic) height
MIT License
1.12k stars 113 forks source link

Consider printing a warning if getTo produces 0 #217

Closed wkillerud closed 6 years ago

wkillerud commented 6 years ago

I'm using React Collapse in a mixed framework world where React views sometimes are mounted inside Marionette views (we're slowly porting a large app to React). A few times now we've struggled getting React Collapse to work, only to discover that we're rendering the React view in the wrong Marionette life cycle method, before stuff is added to the DOM. As a consequence clientHeight is 0 on the first render and the Collapse component always gets a height of 0, regardless of isOpened status.

Would it be possible to add a warning to the console log if getTo produces 0?

https://github.com/nkbt/react-collapse/blob/a0951988f57b6730aec2fde1346467c4d618f761/src/Collapse.js#L150

A message like Collapse measured a clientHeight of 0px. Is the parent element in the DOM and measurable? or something similar would probably have put me on the right track much sooner.

If it sounds OK I'd be happy to file a PR :)

nkbt commented 6 years ago

There is onMeasure callback which you can use to do any extra warnings in your app

https://github.com/nkbt/react-collapse/blob/a0951988f57b6730aec2fde1346467c4d618f761/src/Collapse.js#L106

nkbt commented 6 years ago

Also components will not only expand. They collapse to 0 smoothly too. So 0 is a legit number which should not produce any warnings.

wkillerud commented 6 years ago

Allright, guess we’ll just need to remember this edge case. Thanks for the quick reply!