We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
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
Based on idea from this article:
export default function Img({ src }) { const ref = useClickOutside(handleClickOutside); function handleClickOutside() { console.log("clicked outside"); } return ( <img ref={ref} src={src} alt="comment" /> ); } function useClickOutside(fn) { const ref = useRef(null); useEffect(() => { document.addEventListener("click", handleClick); return () => document.removeEventListener("click", handleClick); }); function handleClick(e) { if (ref.current.contains(e.target)) { return; // inside the element } fn(); }; return ref; }
It probably doesn't cover some edge cases like React.Protals though.
The text was updated successfully, but these errors were encountered:
May want to pass in ref so that it can be used in other hooks. Here's an example: https://usehooks.com/#useOnClickOutside
Sorry, something went wrong.
@gragland yeah, this way it could reuse some existing ref
No branches or pull requests
Based on idea from this article:
It probably doesn't cover some edge cases like React.Protals though.
The text was updated successfully, but these errors were encountered: