Early access. Read the blog post

useClickOutside

The useClickOutside is React hook for handling click events outside of elements.

Basic example  

import {useClickOutside} from '@sanity/ui'

function MyButton () {
  const [buttonElement, setButtonElement] = useState(null)
  
  const handleClickOutside = useCallback(() => {
    console.log('outside')
  }, [])

  useClickOutside(handleClickOutside, [buttonElement])
  
  return <Button ref={setButtonElement} text="Label" />
}

Type  

(
  callback: () => void;
  elements: HTMLElement[];
  boundaryElement?: HTMLElement;
) => (el: HTMLElement | null) => void
Updated Oct 29, 2020 @ 09:42
On this page

Made withby folks at