import {userRef,UseEffect} from "react" function App()=>{ const refOne = useRef(null); useEffect(() => { document.addEventListener("click", handleClickOutside, true); }, []); const handleClickOutside = (e) => { if (refOne.current && !refOne.current.contains(e.target)) { console.log("clicked outside"); } else { console.log(`clicked inside div`); } }; return( <div style={{width:"10rem",height:"10rem", backGround:"red"}}> </div>) }