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,
);
Basic usage of useClickAway hook.
Property | Description | Type | Default |
---|---|---|---|
onClickAway | Trigger Function for ClickAway | (event) => void | - |
target | DOM elements or Ref, support array | Target | Target[] | - |
eventName | The event to be listened, optional | string | click |