Skip to content

Instantly share code, notes, and snippets.

@kevinfelisilda
Last active August 11, 2020 23:55
Show Gist options
  • Save kevinfelisilda/90bc4267936a7cbf0fc866438228f61c to your computer and use it in GitHub Desktop.
Save kevinfelisilda/90bc4267936a7cbf0fc866438228f61c to your computer and use it in GitHub Desktop.
import React, { useRef } from "react";
import useOutsideClick from "./useOutsideClick";
function MyComponent() {
const ref = useRef();
useOutsideClick(ref, () => {
alert('You clicked outside')
});
return (
<div className="App">
<div ref={ref}}>
<h4>This is a menu</h4>
<p>This is another content</p>
</div>
<div>
This is a content outside the menu
</div>
</div>
);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment