Last active
August 11, 2020 23:55
-
-
Save kevinfelisilda/90bc4267936a7cbf0fc866438228f61c to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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