Removing console.log from React Native app

RRikesh picture RRikesh · Aug 14, 2016 · Viewed 19.8k times · Source

Should you remove the console.log() calls before deploying a React Native app to the stores? Are there some performance or other issues that exist if the console.log() calls are kept in the code?

Is there a way to remove the logs with some task runner (in a similar fashion to web-related task runners like Grunt or Gulp)? We still want them during our development/debugging/testing phase but not on production.

Thanks!

Answer

Lucas Bento picture Lucas Bento · Jan 28, 2017

Well, you can always do something like:

if (!__DEV__) {
  console.log = () => {};
}

So every console.log would be invalidated as soon as __DEV__ is not true.