Use click away

Detect if a click event happened outside of an element.

This is custom React Hooks, you need to follow the Basic Rules when you use it.


Click outside the green card to trigger the callback.

APIs / Schnittstellendokumentation


const useClickAway = (
  ref: MutableRefObject<HTMLElement | null>,
  handler: (event: Event) => void,
) => void