New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

@sweepbright/use-click-outside

Package Overview
Dependencies
Maintainers
1
Versions
6
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@sweepbright/use-click-outside

Simple React hook to detect when a click happens outside a component. Useful for implementing modal dialogs and popups.

  • 0.3.0
  • latest
  • npm
  • Socket score

Version published
Weekly downloads
14
decreased by-65.85%
Maintainers
1
Weekly downloads
 
Created
Source

use-click-outside

Simple React hook to detect when a click happens outside a component. Useful for implementing modal dialogs and popups.

Installation

yarn add @sweepbright/use-click-outside
npm install @sweepbright/use-click-outside

Usage

import  {useClickOutside} from '@sweepbright/use-click-outside'


function Popup() {
    const ref= React.useRef(null)
    const onClickOutside = React.useCallback(() => {
        alert('clicked outside element')
    })

    useClickOutside(ref, {
        onClickOutside
    })

    return <div ref={ref}> Hello </div>

}

API

useClickOutside(ref, config, deps)

Params

ref
ParamTypeDescription
refRefObjectA mutable ref object whose current property points target element DOM node
config
ParamTypeDescription
configObjectA configuration object for the behavior of the hook
Config options

The following options are supported

  • onClickOutside: (evt: MouseEvent) => void
    • Required
    • Must be memoized
    • Will be called every time a click outside the target element is detected
    • It is passed the click event object
  • skip: boolean
    • Optional
    • Defaults to false
    • Useful when you want to skip the listener. It can be used as a perf improvement when you know the element target element is not in the DOM.
deps
ParamTypeDescription
depsArrayOptional dependency array

Contributing

TODO

License

MIT

FAQs

Package last updated on 10 Apr 2020

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc