Skip to content

Latest commit

 

History

History
13 lines (9 loc) · 1.71 KB

File metadata and controls

13 lines (9 loc) · 1.71 KB

useClickOutside easy #react #event listeners #hooks

by Pawan Kumar @jsartisan

Take the Challenge

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");
});

Back Share your Solutions Check out Solutions