Skip to content

Latest commit

 

History

History
50 lines (32 loc) · 850 Bytes

README.md

File metadata and controls

50 lines (32 loc) · 850 Bytes

useOnClickAway

It's a 6kb 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.