
Security News
Node.js TSC Votes to Stop Distributing Corepack
Corepack will be phased out from future Node.js releases following a TSC vote.
use-mouse-action
Advanced tools
React Hooks to listen to both mouse down or up and click events with a once called function.
React Hooks to listen to both mouse down or up and click events with a once called function.
This hook can be used to create fast usable drop-down buttons.
npm install use-mouse-action
import useMouseAction from 'use-mouse-action';
const Component = () => {
const props = useMouseAction({
onAction: () => console.log('You clicked or mouse downed me!'),
down: true
});
return (
<button type="button" {...props}>
Click me fast!
</button>
);
};
This library provides three React Hooks:
useMouseAction
useMouseDown
useMouseUp
They all want the same parameter: either the callback function or an options
object with the callback function in the onAction
parameter.
They all return an object of event listeners to add on the element.
import { useMouseDown } from 'use-mouse-action';
/** ... */
const props = useMouseDown(() => toggle);
return (<button type="button" {...props}>Click me</button>);
The useMouseDown
and useMouseUp
are both a shortcut to respectively set the down
and up
option to true
.
onAction
(required): The function called on custom click triggered.down
(default: false
): If the element should listen to mousedown event.up
(default: false
): If the element should listen to mouseup event.touch
(default: false
): If the element should listen to touch equivalent
events.timeout
(default: 10
): Short timeout in milliseconds to prevents multiple
events.You can provide functions that should listen to each event with theses options:
onClick
onMouseDown
onMouseUp
onTouchStart
onTouchEnd
Sometimes, we would like to listen to mousedown
or mouseup
events on
buttons, but these events are difficult to call by disabled peoples or by
people that navigates with their keyboard.
We would like to listen both to mousedown
/mouseup
and click
event, but we
now must to make sure that our action is triggered only once.
Moreover, we would add on top of that the listening of touch events.
That's why I created this React Hooks library.
npm run build
npm test
This project is licensed under the MIT license.
2.0.0 - 2019-04-05
touch
option default to false
because it is in most cases annoying
when scrolling on a touch device.FAQs
React Hooks to listen to both mouse down or up and click events with a once called function.
The npm package use-mouse-action receives a total of 781 weekly downloads. As such, use-mouse-action popularity was classified as not popular.
We found that use-mouse-action 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
Corepack will be phased out from future Node.js releases following a TSC vote.
Research
Security News
Research uncovers Black Basta's plans to exploit package registries for ransomware delivery alongside evidence of similar attacks already targeting open source ecosystems.
Security News
Oxlint's beta release introduces 500+ built-in linting rules while delivering twice the speed of previous versions, with future support planned for custom plugins and improved IDE integration.