Created
August 23, 2021 00:06
-
-
Save PhilippMolitor/1331168daad7b0daae4251a003072d62 to your computer and use it in GitHub Desktop.
Disable React Dev Tools in a safe way, with TypeScript type-safety
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
declare global { | |
interface Window { | |
__REACT_DEVTOOLS_GLOBAL_HOOK__?: Record< | |
string, | |
Map<any, any> | (() => any) | |
>; | |
} | |
} | |
export function disableDevTools(): void { | |
if (!window.__REACT_DEVTOOLS_GLOBAL_HOOK__) return; | |
Object.keys(window.__REACT_DEVTOOLS_GLOBAL_HOOK__).forEach((k) => { | |
let replacement: undefined | Map<unknown, unknown>; | |
if (k === 'renderers') replacement = new Map(); | |
window.__REACT_DEVTOOLS_GLOBAL_HOOK__![k] = | |
replacement || (() => undefined); | |
}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment