-
Notifications
You must be signed in to change notification settings - Fork 113
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Exposing onHeightReady hook #43
Conversation
var isOpenedChanged = isOpened !== this.props.isOpened; | ||
this.setState({isOpenedChanged}, () => { | ||
if (this.props.onHeightReady && isOpenedChanged) { | ||
this.props.onHeightReady(isOpened ? this.state.height : 0); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think doing "side-effect" (notifying parent) in componentWillReceiveProps is dangerous. It also would potentially end up in recursion.
Potentially this could be added to some other lifecycle method.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'll look into using componentDidUpdate
instead. Shouldn't really be a problem
Thanks a lot for your PR. I guess it might be helpful to notify about current height, though I need to do some more testing with it. Can you please, add an example of how you use it? That would help a lot to understand reasoning better for everyone (me included 😄) |
Current coverage is
|
…er to componentDidUpdate
The onHeightReady example manipulates window.scroll, and thus needs a make-shift DOM during test.
Fixed the issues highlighted in the initial review, and added an example of a potential usecase, autoscrolling, see example 7 and Hooks.js. For simplicity I've included a devDependency for the scrolling. |
Sorry for the delay, was not able to check it properly |
No problem. Just happy that it got merged. :) Let me know if there is anything else you need me to do. |
For when you need to animate scroll or elements outside of the collapse-component.
Don't know if this is the best solution, or even if it should be part of this library. But it did allow me to add scroll-animation alongside the expanding-component.