Search code examples
performanceautomationreact-nativeconsole.log

Removing console.log from React Native app


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.


Solution

  • believe best practice is to wrap your debug code in statements such as...

        if(__DEV__){
            console.log();
        }
    

    This way, it only runs when you're running within the packager or emulator. More info here... https://facebook.github.io/react-native/docs/performance#using-consolelog-statements

    This would also work...

    __DEV__ && console.log('logged only in __DEV__');