Awesome Open Source
Awesome Open Source

use-onclickoutside

React hook for listening for clicks outside of an element.

Usage

import * as React from 'react'
import useOnClickOutside from 'use-onclickoutside'

export default function Modal({ close }) {
  const ref = React.useRef(null)
  useOnClickOutside(ref, close)

  return <div ref={ref}>{'Modal content'}</div>
}

Get A Weekly Email With Trending Projects For These Topics
No Spam. Unsubscribe easily at any time.
javascript (68,104
react (5,175
reactjs (1,029
hooks (243
hook (123

Find Open Source By Browsing 7,000 Topics Across 59 Categories