Pomax / react-onclickoutside

An onClickOutside wrapper for React components
MIT License
1.82k stars 187 forks source link

findDOMNode is deprecated in React StrictMode #369

Closed Ruslan101 closed 1 month ago

Ruslan101 commented 2 years ago

I used the react-onclickoutside (6.12.0) and I got this warning from React:

Warning: findDOMNode is deprecated in StrictMode. findDOMNode was passed an instance of AddExtModal which is inside StrictMode. Instead, add a ref directly to the element you want to reference. Learn more about using refs safely here: https://reactjs.org/link/strict-mode-find-node at onClickOutside (http://mySiteName/static/js/vendors~main.chunk.js:77178:26)

Nantris commented 2 years ago

This seems not very clean and easy to fix. Any solution is going to involve merging refs, if I'm not mistaken. Not impossible, but it's not gonna be pretty.

Pomax commented 2 years ago

Given the advances in JS, particularly the contains function, there might finally be a simple solution here, since we only need the HoC's own ref to determine whether clicks are inside or outside of the local DOM tree. I'll see if I have some time soon to pen a revision.

JiDarwish commented 2 years ago

Any update on this issue :) ?

Pomax commented 2 years ago

If you're using hooks: yes. If you're using component classes, not yet.

No time estimate on when it'll get done either, but if you want to pay for the time necessary to fix this, feel free to reach out and I can move this up to the top of the queue to get it done in the next few days.

MrDevin12 commented 2 years ago

What amount of funding might you need to resolve this? @Pomax

Pomax commented 2 years ago

Uplifting dependencies and testing for v17, updating the code and writing additional test, updating the docs, and "not spending time on the things that were on the top of the to-do list" would probably put it at around $1000 (which I fully realise is well beyond the donation budget of an individual, but is a trivial one-time expense for a company that relies on open source)

konossow commented 1 month ago

It will be removed in React 19, see: https://react.dev/blog/2024/04/25/react-19-upgrade-guide#removed-reactdom-finddomnode

Pomax commented 1 month ago

Thankfully ("thankfully"), no one needs this HoC anymore because React unfortunately went all-in on hooks, and the README.md gives you alternative code that'll do what you want without needing to install anything.