Security News
Research
Data Theft Repackaged: A Case Study in Malicious Wrapper Packages on npm
The Socket Research Team breaks down a malicious wrapper package that uses obfuscation to harvest credentials and exfiltrate sensitive data.
react-click-away-listener
Advanced tools
npm install react-click-away-listener
or
yarn add react-click-away-listener
import ClickAwayListener from 'react-click-away-listener';
const App = () => {
const handleClickAway = () => {
console.log('Maybe close the popup');
};
return (
<div id="app">
<ClickAwayListener onClickAway={handleClickAway}>
<div>
{' '}
Triggers whenever a click event is registered outside this div element{' '}
</div>
</ClickAwayListener>
</div>
);
};
v2.0.0 has breaking changes which uses the React.Children.only
API.
Thus, the following caveats apply for the children
of the <ClickAwayListener>
component:
<ClickAwayListener>
component.<ClickAwayListener>
component.Violating the above caveats will result in the following error:
Error: Element type is invalid: expected a string (for built-in components) or a class/function (for composite components) but got: undefined. You likely forgot to export your component from the file it's defined in, or you might have mixed up default and named imports.
Check the render method of `ClickAwayListener`.
If you have multiple child components to pass, you can simply wrap them around a React Fragment like so:
// Assume the `handleClickAway` function is defined.
<ClickAwayListener onClickAway={handleClickAway}>
<>
<p>First paragraph</p>
<button>Example Button</button>
<p>Second paragraph</p>
</>
</ClickAwayListener>
Or if you only have text nodes, you can also wrap them in a React Fragment like so:
// Assume the `handleClickAway` function is defined.
<ClickAwayListener onClickAway={handleClickAway}>
<>First text node Second text node</>
</ClickAwayListener>
Name | Type | Default | Description |
---|---|---|---|
onClickAway | (event) => void | Fires when a user clicks outside the click away component | |
mouseEvent | 'click' | 'mousedown' | 'mouseup' | 'click' | The mouse event type that gets fired on ClickAway |
touchEvent | 'touchstart' | 'touchend' | 'touchend' | The touch event type that gets fired on ClickAway |
focusEvent | 'focusin' | 'focusout' | 'focusin' | The focus event type that gets fired on ClickAway |
MIT
FAQs
A simple click away listener built with React Hooks
We found that react-click-away-listener demonstrated a healthy version release cadence and project activity because the last version was released less than 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
Research
The Socket Research Team breaks down a malicious wrapper package that uses obfuscation to harvest credentials and exfiltrate sensitive data.
Research
Security News
Attackers used a malicious npm package typosquatting a popular ESLint plugin to steal sensitive data, execute commands, and exploit developer systems.
Security News
The Ultralytics' PyPI Package was compromised four times in one weekend through GitHub Actions cache poisoning and failure to rotate previously compromised API tokens.