-
Notifications
You must be signed in to change notification settings - Fork 727
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
Add initialHeight
and initialWidth
to withParentSize
#836
Conversation
Pull Request Test Coverage Report for Build 77
💛 - Coveralls |
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.
In my opinion, this change should be reverted. It is an anti-pattern as you can see here https://reactjs.org/docs/react-component.html#constructor if you scroll down a little bit to the Note
section.
A better solution would be to modify the render
function like so:
render() {
+ const { initialWidth, initialHeight } = this.props;
+ const { parentWidth = initialWidth, parentHeight = initialHeight } = this.state;
- const { parentWidth, parentHeight } = this.state;
return (
<div style={CONTAINER_STYLES} ref={this.setRef}>
thanks for the PR @shannonrothe! I'm okay with this implementation or @wyze 's suggestion. The react docs highlight that it's an anti-pattern if you are expecting Let me know which you prefer and we can merge this puppy 🚀 . |
Yeah I thought it would be implied that those values wouldn't update but I think @wyze's suggestion is a little nicer. I've fixed up so should be ready to merge 👍 |
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.
Awesome, thanks @shannonrothe!
🚀 Enhancements
Adds the ability to set
initialWidth/initialHeight
to@visx/responsive
swithParentSize
. Closes #554.