How to do logging in React Native?

前端 未结 30 3538
不思量自难忘°
不思量自难忘° 2020-11-30 17:08

How can I log a variable in React Native, like using console.log when developing for web?

30条回答
  •  孤城傲影
    2020-11-30 17:43

    I had the same issue: console messages were not appearing in XCode's debug area. In my app I did cmd-d to bring up the debug menu, and remembered I had set "Debug in Safari" on.

    I turned this off, and some messages were printed to the output message, but not my console messages. However, one of the log messages said:

    __DEV__ === false, development-level warning are OFF, performance optimizations are ON"
    

    This was because I had previously bundled my project for testing on a real device with the command:

    react-native bundle --minify
    

    This bundled without "dev-mode" on. To allow dev messages,include the --dev flag:

    react-native bundle --dev
    

    And console.log messages are back! If you aren't bundling for a real device, don't forget to re-point jsCodeLocation in AppDelegate.m to localhost (I did!).

提交回复
热议问题