-
-
Notifications
You must be signed in to change notification settings - Fork 186
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
Problem when using hooks + multiple components #329
Comments
This HOC works based on the assumption that it wraps true instances, so if you use a functional component, and you only use one of them on a page, it will likely work, but if you use more than one, the last one "wins" and is the only one that'll work because the |
I see... there is any way to get around that? Should I use a new HOC for every component? Why the functional difference matters here? |
I have this issue as well, will there be a fix for this? |
can we use class component to fix it ? |
https://codesandbox.io/s/loving-newton-754t8 |
This line is the problem. This ties a static method to a single instance, which is a serious anti-pattern in React. The class-based usage is fine, because it uses an instance method instead of a static method. |
Makes sense, don't know why I didn't realised about it before... |
The linked example in this section (https://github.com/Pomax/react-onclickoutside#functional-component-with-usestate-hook) will demonstrate this bug if you put 2 Menu components in index.js |
Is this something that will be addressed in a future release? |
The previously used library was broken in the hooks implementation: Pomax/react-onclickoutside#329 Replaced it with https://www.npmjs.com/package/use-onclickoutside
The previously used library was broken in the hooks implementation: Pomax/react-onclickoutside#329 Replaced it with https://www.npmjs.com/package/use-onclickoutside
* WEBREF-21 Refactor EventDropdownFilter to use hooks * WEBREF-21 Fix broken onClickOutside functionality in EventDropDownFilter The previously used library was broken in the hooks implementation: Pomax/react-onclickoutside#329 Replaced it with https://www.npmjs.com/package/use-onclickoutside * WEBREF-21: Refactor to use context hook * WEBREF-21: Replace shouldComponentUpdate with React.memo * WEBREF-21: Fix useContext * Add comment about broken react-onclickoutside lib * Destructure AppContext state * WEBREF-21 Remove useEffect and refactor context
Managed to resolve it with introducing unique name (id) for the component. So, imagine we have
And config:
Though, this is a dirty workaround, hope it would help someone. |
@metalass you sir deserve a medal! Worked like a charm in "react": "^16.13.1" and "react-onclickoutside": "^6.9.0". |
OMG. Thank you for this @metalass. It's a workaround but it definitely works and makes sense!! |
Ty @metalass , worked fine on "react": "^17.0.1" and "react-onclickoutside": "^6.9.0" |
Using this hook also works https://usehooks.com/useOnClickOutside/. |
Hi everyone,
I'm having a problem, I've been using this library for a while working 100%. Today I tried to implement it in another part of my code, and it just don't work properly. I've tried this in version
6.8.0
and6.9.0
.Here's my code:
If I only use this in one component, everything works properly. If I two or more components, it breaks.
EDIT:
Also made a simple example: https://codesandbox.io/embed/react-onclickoutside-bug-report-jc963
The text was updated successfully, but these errors were encountered: