#2 useClickOutside

easy
react
event listeners
hooks

Implement a custom hook useClickOutside to handle the click outside of the passed ref element. The hook takes a callback function which will be invoked when the user clicks outside of the passed ref element.

const ref = useRef(null);

useClickOutside(ref, () => {
  console.log("clicked outside");
});