@donavon/prevent-default
v1.0.1
Published
A wrapper that calls event.preventDefault() for you.
Downloads
7
Maintainers
Readme
@donavon/prevent-default
A wrapper that calls event.preventDefault() for you.
Install
> npm i @donavon/prevent-default --save
Usage
To use prevent-default
, simply import
it (ES6) and wrap your onClick
with pd()
as shown below.
Although useful with React components, it is not React specific and can be used without React.
import pd from "@donavon/prevent-default";
const noClicking = () => {
alert("You can't click here, buddy!");
}
const MyLinkComponent = ({ children }) => {
return (
<a href="#" onClick={pb(noClicking)}>
{children}
</a>
);
};
export default MyLinkComponent;
Don't recognize the format of the React component shown above? It's stateless. You should be using stateless components in your app when applicable.