Newlyweds Proposing Marriage
Publish your own packages to the world's most popular software ecosystem with npm Pro.Get started »

@donavon/prevent-default

1.0.1 • Public • Published

@donavon/prevent-default

Build Status

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.

Install

npm i @donavon/prevent-default

DownloadsWeekly Downloads

1

Version

1.0.1

License

MIT

Last publish

Collaborators

  • avatar