Last active
May 6, 2024 11:12
-
-
Save srikiranvelpuri/89e31a946b2968cf0114c746ff8fbf9b to your computer and use it in GitHub Desktop.
React cusotm hook to diable inspect
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* React cusotm hook to disable inspect | |
*/ | |
export const useDisableInspect = () => { | |
useEffect(() => { | |
const disableRightClick = (e) => { | |
e.preventDefault(); | |
}; | |
const handleKeyDown = (e) => { | |
const ctrlShiftKey = (keyCode) => | |
e.ctrlKey && e.shiftKey && e.keyCode === keyCode.charCodeAt(0); | |
if ( | |
e.keyCode === 123 || | |
ctrlShiftKey("I") || | |
ctrlShiftKey("J") || | |
ctrlShiftKey("C") || | |
(e.ctrlKey && e.keyCode === "U".charCodeAt(0)) | |
) { | |
e.preventDefault(); | |
} | |
}; | |
document.addEventListener("contextmenu", disableRightClick); | |
document.addEventListener("keydown", handleKeyDown); | |
return () => { | |
document.removeEventListener("contextmenu", disableRightClick); | |
document.removeEventListener("keydown", handleKeyDown); | |
}; | |
}, []); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment