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.

Default

Click outside the green card to trigger the callback.

APIs

useClickAway

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