Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

vczb/use-on-click-away

Repository files navigation

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.

About

Tiny (6kb) hook for catching outside clicks

Topics

Resources

License

Stars

Watchers

Forks

AltStyle によって変換されたページ (->オリジナル) /