Skip to content

donavon/prevent-default

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

@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.

About

A wrapper that calls `event.preventDefault()` for you.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published