Skip to content

fix(@toss/react): improve readability and add dependencies useOutsideClickEffect #481

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

Merged
merged 2 commits into from
May 26, 2024

Conversation

Collection50
Copy link
Contributor

Overview

AS-IS

useEffect(() => {
  containers.current = (Array.isArray(container) ? container : [container]).filter(isNotNil);
}, [container]);
useEffect(() => {
  document.addEventListener('click', handleDocumentClick);
  document.addEventListener('touchstart', handleDocumentClick);

  return () => {
    document.removeEventListener('click', handleDocumentClick);
    document.removeEventListener('touchstart', handleDocumentClick);
  };
}, []);

TO-BE

useEffect(() => {
  containers.current = [container].flat(1).filter(isNotNil);
}, [container]);
useEffect(() => {
  document.addEventListener('click', handleDocumentClick);
  document.addEventListener('touchstart', handleDocumentClick);

  return () => {
    document.removeEventListener('click', handleDocumentClick);
    document.removeEventListener('touchstart', handleDocumentClick);
  };
}, [handleDocumentClick]);

PR Checklist

  • I read and included theses actions below
  1. I have read the Contributing Guide
  2. I have written documents and tests, if needed.

close #449

…Effect order to improve readability, add dependencies
Copy link

vercel bot commented May 24, 2024

@Collection50 is attempting to deploy a commit to the Toss Team on Vercel.

A member of the Team first needs to authorize it.

@okinawaa
Copy link
Member

The flat method was introduced in ES2019 (ES10). Therefore, this code will work well in modern browsers, but it might not be supported in older browsers. Is this acceptable?

@Collection50
Copy link
Contributor Author

The flat method was introduced in ES2019 (ES10). Therefore, this code will work well in modern browsers, but it might not be supported in older browsers. Is this acceptable?

The part I was looking for was the flat !

I'd appreciate it if you could tell me how to know the current status of support for the older browser you mentioned!

Copy link
Member

@okinawaa okinawaa left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We don't have a specific browser range! yet
According to the link you sent me, it says it complies with the baseline.
I think that's enough!

@okinawaa okinawaa enabled auto-merge (squash) May 26, 2024 12:58
@okinawaa okinawaa merged commit cbd7278 into toss:main May 26, 2024
5 of 6 checks passed
@Collection50
Copy link
Contributor Author

We don't have a specific browser range! yet According to the link you sent me, it says it complies with the baseline. I think that's enough!

Thank you!!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Question]:useOutsideClickEffect dependancies
2 participants