Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save srikiranvelpuri/89e31a946b2968cf0114c746ff8fbf9b to your computer and use it in GitHub Desktop.
Save srikiranvelpuri/89e31a946b2968cf0114c746ff8fbf9b to your computer and use it in GitHub Desktop.
React cusotm hook to diable inspect
/**
* 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