-
Notifications
You must be signed in to change notification settings - Fork 4.2k
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
Remove findDomNode from withHoverAreas by making a render prop component #11407
Conversation
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.
Nice!
I tested this by hovering my mouse over different blocks in the demo post and nothing seems to have regressed.
Left some minor suggestions on how to improve the comprehensibility of WithHoverAreas
.
Some unit tests for WithHoverAreas
would be ace, but since they're missing in master
that's not a blocker.
{ shouldShowMobileToolbar && ( | ||
<BlockMobileToolbar | ||
<WithHoverAreas> | ||
{ ( { bindContainer, hoverArea } ) => { |
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.
Did you consider changing BlockListBlock
to use createRef()
and then having it share this ref with <WithHoverArea>
?
<WithHoverAreas containerRef={ this.blockListRef }>
{ ( hoverArea ) => {
...
} }
</WithHoverAreas>
I think this makes it a little clearer that the "container" is something that's passed in to WithHoverAreas
.
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.
Good ideal, I'll try it.
if ( this.state.hoverArea ) { | ||
this.setState( { hoverArea: null } ); | ||
} | ||
toggleListeners( shouldRemoveEvents ) { |
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 would expect the sole boolean argument of toggleListeners
to work the opposite way.
this.toggleListeners( true ); // Adds the listeners
this.toggleListeners( false ); // Removes the listeners
this.onMouseLeave = this.onMouseLeave.bind( this ); | ||
this.onMouseMove = this.onMouseMove.bind( this ); | ||
} | ||
class WithHoverAreas extends Component { |
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.
The convention we seem to follow is that components beginning with with
are HOCs. In other places that we've used components with render props, we've named it something more conventional, e.g. PostTaxonomies
.
(HoverArea
would be my suggestion here.)
3caeb8c
to
3f15f77
Compare
Related #11360
This PR removes
findDOMNode
from thewithHoverAreas
Higher Order Component by making it a component with a render prop. (This would be the perfect use-case for a React hook :) )Make sure to view the diff without "whitespace" diff