Skip to content

Instantly share code, notes, and snippets.

@rrrhys
Created September 28, 2018 04:53
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rrrhys/07f7f46278375d897f3880868e82d9b5 to your computer and use it in GitHub Desktop.
Save rrrhys/07f7f46278375d897f3880868e82d9b5 to your computer and use it in GitHub Desktop.
Check if the debugger is attached in a React Native project.
// setTimeout (and other wait related code) fails when a debugger is attached to React Native.
// in DebuggerCheck.ts
let _looksLikeDebuggerAttached = true;
setTimeout(() => {
_looksLikeDebuggerAttached = false;
}, 1);
export default {
debuggerIsAttached: () => {
return _looksLikeDebuggerAttached;
}
}
// end DebuggerCheck.ts
//----
// how to use:
import DebuggerCheck from './DebuggerCheck';
if(DebuggerCheck.debuggerIsAttached()){
// handle settimeout differently etc
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment