Socket
Book a DemoInstallSign in
Socket

@pacote/react-use-outside

Package Overview
Dependencies
Maintainers
0
Versions
23
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@pacote/react-use-outside

React hook to capture mouse or touch events outside a component.

2.0.4
latest
npmnpm
Version published
Weekly downloads
65
116.67%
Maintainers
0
Weekly downloads
 
Created
Source

@pacote/react-use-outside

version minified minified + gzip

Hook to handle events outside React components.

Installation

yarn add @pacote/react-use-outside

Usage

useOutside<T>(type: Array<keyof DocumentEventMap> | keyof DocumentEventMap, listener: EventListener): React.RefObject<T>

Takes one or more event types to listen and an event listener function and returns a reference which can be applied to a DOM element. The provided function will be called for all listened events triggered outside the component.

import React from 'react'
import { useOutside } from '@pacote/react-use-outside'

const Modal = () => {
  const ref = useOutside('click', () => {
    console.log('Clicked outside!')
  })

  return <div ref={ref}>Click outside to show console message.</div>
}

License

MIT © Luís Rodrigues.

Keywords

react

FAQs

Package last updated on 25 Feb 2025

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

About

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.

  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc

U.S. Patent No. 12,346,443 & 12,314,394. Other pending.