Skip to content

Instantly share code, notes, and snippets.

@PhilippMolitor
Created August 23, 2021 00:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save PhilippMolitor/1331168daad7b0daae4251a003072d62 to your computer and use it in GitHub Desktop.
Save PhilippMolitor/1331168daad7b0daae4251a003072d62 to your computer and use it in GitHub Desktop.
Disable React Dev Tools in a safe way, with TypeScript type-safety
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