Skip to content

Commit

Permalink
Merge pull request #16 from mgrycz/useOutsideClick-receives-event-arg…
Browse files Browse the repository at this point in the history
…ument

feat: onOutsideClick callback function receives an event argument
  • Loading branch information
roblan committed Oct 21, 2022
2 parents 8457e9c + 69cc66b commit a3774a2
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,14 @@ const useClickOutside = (onOutsideClick) => {
}

let timeoutId;
const clickHandler = () => {
const clickHandler = (event) => {
// This event handler will always be called, as long as the Component using this hook
// is mounted. It will be called each time click event is captured in the document.
// Because it is attached to the document object, it will be called before the React
// onClickCapture event handler which is attached to the 'root' element (document's descendant).
// That's why we need to postpone it one loop cycle, to make sure the React's handler
// executes first.
timeoutId = setTimeout(onOutsideClick, 0);
timeoutId = setTimeout(onOutsideClick, 0, event);
callbackTimeoutId.current = timeoutId;
};

Expand Down

0 comments on commit a3774a2

Please sign in to comment.