2.0.3 • Published 9 months ago
@pacote/react-use-outside v2.0.3
@pacote/react-use-outside
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.
2.0.3
9 months ago
2.0.2
2 years ago
2.0.1
2 years ago
2.0.0
2 years ago
1.1.11
3 years ago
1.1.9
4 years ago
1.1.8
4 years ago
1.1.7
5 years ago
1.1.6
5 years ago
1.1.5
5 years ago
1.1.4
5 years ago
1.1.3
5 years ago
1.1.2
5 years ago
1.1.1
5 years ago
1.1.0
6 years ago
1.0.6
6 years ago
1.0.5
6 years ago
1.0.4
6 years ago
1.0.3
6 years ago
1.0.2
6 years ago
1.0.1
6 years ago
1.0.0
6 years ago