useClickAway

A hook that can manage click outside of target element(s).

type Target = HTMLElement | React.MutableRefObject | () => HTMLElement;

useClickAway(
  onClickAway: (event: MouseEvent | TouchEvent) => void,
  target: Target | Target[],
  eventName?: string,
);

Example

Basic usage of useClickAway hook.

API

PropertyDescriptionTypeDefault
onClickAwayTrigger Function for ClickAway(event) => void-
targetDOM elements or Ref, support arrayTarget | Target[]-
eventNameThe event to be listened, optionalstringclick
ON THIS PAGE