react-outside-handler
v1.0.3
Published
React library for detecting events outside of element
Downloads
4
Readme
react-outside-handler
React library for detecting events outside of element
Installation
npm i react-outside-handler
Usage
import {useOutsideHandler} from "react-outside-handler";
export const OutsideHandler = () => {
const { ref } = useOutsideHandler("click", () => {
// event code
})
return <div>
{/* Internal elements including this element do not execute 'event code' when click */}
<div ref={ref}>
<p>Element</p>
</div>
{/* Click on this element will execute 'event code' */}
<button>Outside Element</button>
</div>
}