use-on-click-away
TypeScript icon, indicating that this package has built-in type declarations

0.1.1 • Public • Published

useOnClickAway

It's a 12kb React custom hook that catches clicks outside of the element it is applied to.

Installation

use-on-click-away is available as an npm package.

To install it, run:

  //with npm
  npm install use-on-click-away

  //with yarn
  yarn add use-on-click-away

Example

use-on-click-away-demo

Usage

const MyComponent = () => {
  const ref = useRef()

  useOnClickAway(ref, () => {
    console.log('clicked away')
  })

  return (
    <div ref={ref}>
      ...
    </div>
  )

}

export default MyComponent

Contributing

You can contribute by opening an issue or sending a pull request.

License

This project is licensed under the MIT License.

Readme

Keywords

Package Sidebar

Install

npm i use-on-click-away

Weekly Downloads

0

Version

0.1.1

License

MIT

Unpacked Size

6.37 kB

Total Files

11

Last publish

Collaborators

  • vczb