-
Notifications
You must be signed in to change notification settings - Fork 0
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
Rewrite <HoverLayer> using Hooks #10
Conversation
return ( | ||
<> | ||
{detectionAreas} | ||
</> |
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.
Maybe we don't need the Fragment, just return detectionAreas
as previous code?
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.
This is necessary for Typescript because if detectionAreas
were not wrapped by Fragment, <HoverLayer>
would not be a legit FunctionComponent
.
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.
Interesting 🤕 I just tried directly return detectionAreas
and the typescript complier / tslint didn't have any error / warning for this.
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.
Looks great! Needs to tweak some issues around useCallback
, though.
}, | ||
throttleTime, | ||
), | ||
[], |
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 the second args should be [handleHover, setHoveredPosAndIndex, throttleTime]
. The throttled function should change if one of these props changes. See the note part of useCallback doc.
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.
Great catch. Thanks for finding this out 😃
event.persist(); | ||
updatePosition(dataIndex, event); | ||
}, | ||
[], |
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.
Same as the comment above (L63).
updatePosition.cancel(); | ||
clearHovering(); | ||
}, | ||
[], |
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.
Same as the comment above with one more clearHovering
argument in input arrays.
@chenesan Thanks for reminding me about the correct usage of |
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.
Looks good to me now 👍
Purpose
This PR follows the rewrites using Hooks (#8, #9). It converts as a functional component.
In addition, to better reuses the process of requesting animation frame, it adds a new custom effect
useAnimationFrame
of which users can simply call itsrequestWindowAnimationFrame
, and it will cancel the animation frame when the component is going to be unmounted.Changes