
Company News
Meet the Socket Team at RSAC and BSidesSF 2026
Join Socket for live demos, rooftop happy hours, and one-on-one meetings during BSidesSF and RSA 2026 in San Francisco.
outsideclick-react
Advanced tools
This is a lightweight React package that provides a hook and component for detecting clicks outside of a specified element.
outsideclick-react is a lightweight React package that provides a hook and component for detecting clicks outside of a specified element. This can be useful for creating dropdown menus, modals, and other UI components that need to close when the user clicks outside of them.
You can install outsideclick-react using NPM or Yarn:
npm install outsideclick-react
or
yarn add outsideclick-react
A hook that returns a ref object that can be attached to a target element to detect clicks outside of it.
import { useOutsideClick } from "outsideclick-react";
function MyComponent() {
const handleOutsideClick = (e)=> {
// Handle outside click
}
const ref = useOutsideClick(handleOutsideClick)
/* const ref = useOutsideClick(handleOutsideClick,".hello-ignore") */
return(
<div ref={ref}>
{/* Your component */}
</div>
)
}
In this example, we're using the useOutsideClick hook returns a ref object that can be used to detect clicks outside of an element. Pass in a handleOutsideClick function as a parameter to the hook, and when a click outside of the target element is detected, the function is called with the event object as the argument. This allows you to perform any necessary actions in response to the click.
Alternatively, you can use the OutsideClick component provided by the package to wrap your component:
import { OutsideClick } from 'outsideclick-react'
function MyComponent() {
return (
<OutsideClick
onOutsideClick={() => {
/* Handle outside click */
}}
ignoreElement=".ignore"
>
<div>{/* Your component */}</div>
</OutsideClick>
)
}
In the example above, we use the OutsideClick component to wrap our component and pass a callback function to the onOutsideClick prop that will be called when a click occurs outside of the wrapped element.
Note: The
OutsideClickcomponent returns a div element and supports all of the properties of a standard div element.
In case you want support my work
FAQs
A React utility hook for detecting outside clicks
We found that outsideclick-react demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 0 open source maintainers collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Company News
Join Socket for live demos, rooftop happy hours, and one-on-one meetings during BSidesSF and RSA 2026 in San Francisco.

Research
/Security News
Malicious Packagist packages disguised as Laravel utilities install an encrypted PHP RAT via Composer dependencies, enabling remote access and C2 callbacks.

Research
/Security News
OpenVSX releases of Aqua Trivy 1.8.12 and 1.8.13 contained injected natural-language prompts that abuse local AI coding agents for system inspection and potential data exfiltration.