React hook for listening for clicks outside of an element.
Clone or download
Latest commit 6c6b4bd Nov 11, 2018
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
src Use are-passive-events-supported Nov 10, 2018
.babelrc.js Use are-passive-events-supported Nov 10, 2018
.gitignore Working hook Oct 29, 2018
.huskyrc Working hook Oct 29, 2018
.lintstagedrc Use are-passive-events-supported Nov 10, 2018
.npmrc Working hook Oct 29, 2018
.prettierrc Use are-passive-events-supported Nov 10, 2018
.travis.yml Working hook Oct 29, 2018
README.md Working hook Oct 29, 2018
package.json 0.2.2 Nov 10, 2018
rollup.config.js Working hook Oct 29, 2018

README.md

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()
  useOnClickOutside(ref, close)

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