RUI.next

Hooks
useClickAway

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,
);
type Target = HTMLElement | React.MutableRefObject | () => HTMLElement;

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

Example

Basic usage of useClickAway hook.

Multiple DOM elements
Test A img

Test B button



Click outside count: 0

API

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