-
Notifications
You must be signed in to change notification settings - Fork 46
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
**Feature:** <Foldable /> component to React hook #916
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.
Beautiful, but I'd request one change.
@TejasQ can you kindly review again. |
I am sorry I don't understand, The mouse state seems to be toggling fine at my end via the deployment link for this PR. What is that I am missing here? 🤔 I find this as the same behavior as on the https://operational-ui.netlify.com/#Foldable demo as well, please correct me where I am wrong 😅 @TejasQ |
No problem at all!
I'm not sure this is true. I think you may not be testing it correctly.
Let's clarify with a GIF showing the current Notice how on Are you able to reproduce this? |
Yes thank you, I am on it. |
Can you kindly review again. @TejasQ 🤞 |
@adeelibr great work! 🎉 Let's get one last review from @fabien0102. Can you explain how you fixed it? |
+ React.useEffect(() => {
+ document.addEventListener("mousemove", handleMouseMove)
+ return () => document.removeEventListener("mousemove", handleMouseMove)
- }, [])
+ }) Removing The current implementation ensures that as soon as we |
public componentWillUnmount() { | ||
document.removeEventListener("mousemove", this.handleMouseMove) | ||
} | ||
React.useEffect(() => { |
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.
use effect will run after each render unless you instruct it not to do so with the second param
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.
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.
Having a look at Dan Abramov's at React Conf 2018 https://youtu.be/V-QO-KO90iQ?t=2475 He isn't monitoring that with a second param. For event listeners.
use effect will run after each render unless you instruct it not to do so with the second param
That is okay! I believe, I have tested this. As soon as I mouse over a the "mousemove" event is binded & as soon as I mouse out the "mousemove" is removed from the DOM for that element. & I think this is the correct behavior. We shouldn't listen to an event continuously which might not get used.
@adeelibr let's do a fix in a separate PR. |
Summary
Convert Foldable from React class component to React hook.
Related issue
#910
To be tested
Me
localhost:6060