react-outside-handler
TypeScript icon, indicating that this package has built-in type declarations

1.0.3 • Public • Published

react-outside-handler

NPM License NPM Version

React library for detecting events outside of element

Installation

npm i react-outside-handler

Usage

import {useOutsideHandler} from "react-outside-handler";

export const OutsideHandler = () => {
    const { ref } = useOutsideHandler("click", () => {
        // event code
    })

    return <div>
        {/* Internal elements including this element do not execute 'event code' when click */}
        <div ref={ref}>
            <p>Element</p>
        </div>

        {/* Click on this element will execute 'event code' */}
        <button>Outside Element</button>
    </div>
}

Package Sidebar

Install

npm i react-outside-handler

Weekly Downloads

2

Version

1.0.3

License

MIT

Unpacked Size

10.9 kB

Total Files

20

Last publish

Collaborators

  • middly