npm i -s @miyauci/react-click-outside
or
yarn add @miyauci/react-click-outside
This provides React Custom Hooks.
import React, { useRef } from 'react'
import { useClickOutside } from '@miyauci/react-click-outside'
const App: FC = () => {
const ref = useRef<HTMLElement>(null)
const onClick = () => console.log('Outside clicked')
useClickOutside(ref, onClick)
return (
<div>
Outer
<div ref={ref}>
<div>Inter</div>
</div>
</div>
)
}