
Security News
Meet Socket at Black Hat and DEF CON 2025 in Las Vegas
Meet Socket at Black Hat & DEF CON 2025 for 1:1s, insider security talks at Allegiant Stadium, and a private dinner with top minds in software supply chain security.
react-use-clickout
Advanced tools
custom react hook to handle an event on click ouside of a component
It's a custom hook that handles an event after clicking out of the component
Alright, let's go. First you should install the library
Using yarn
yarn add react-use-clickout
Or npm
npm i react-use-clickout
Prefer to install it derectly on your project, not globally
import React from 'react';
import useClickout from 'react-use-clickout';
function App() {
const [
ref, // it's to be assigned to the component reference
bindHandler // it's a function to bind a callback handler
] = useClickout();
/**
* The function passed as a callback will be called
* if clicked out of the referenced component
*/
bindHandler(() => {
console.log('clickout');
});
return (
<div>
<p ref={ref}>
Referenced component
</p>
<div>
It's out of the referenced component
</div>
</div>
);
}
export default App;
Changing Events is possible. You can pass an array with the events to be listened. The default are mousedown
and touchstart
.
const [ref, bindClickout] = useClickout(['click']);
Although the name of this library is clickout, it isn't only about click event.
It has the react@^16.8.0
and react-dom@^16.8.0
as peer-dependencies
FAQs
custom react hook to handle an event on click ouside of a component
The npm package react-use-clickout receives a total of 4 weekly downloads. As such, react-use-clickout popularity was classified as not popular.
We found that react-use-clickout demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer 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.
Security News
Meet Socket at Black Hat & DEF CON 2025 for 1:1s, insider security talks at Allegiant Stadium, and a private dinner with top minds in software supply chain security.
Security News
CAI is a new open source AI framework that automates penetration testing tasks like scanning and exploitation up to 3,600× faster than humans.
Security News
Deno 2.4 brings back bundling, improves dependency updates and telemetry, and makes the runtime more practical for real-world JavaScript projects.