How to do logging in React Native?

前端 未结 30 3061
不思量自难忘°
不思量自难忘° 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:22

    There are 3 methods that I use to debug when developing React Native apps:

    1. console.log(): shows in console
    2. console.warn(): shows in yellow box bottom of application
    3. alert(): shows as a prompt just like it does in web
    0 讨论(0)
  • 2020-11-30 17:22

    Chrome Devtool is the best and easiest way for logging and debugging.

    0 讨论(0)
  • 2020-11-30 17:23

    Press [command + control + Z] in Xcode Simulator, choose Debug JS Remotely, then press [command + option + J] to open Chrome developer tools.

    Xcode Simulator Img

    refer:Debugging React Native Apps

    0 讨论(0)
  • 2020-11-30 17:23

    You use the same thing that is used for regular web. The console command also works in this case. For example, you can use console.log(), console.warn(), console.clear() etc.

    You can use Chrome Developer to use the console command when you're logging while you are running your React Native app.

    0 讨论(0)
  • 2020-11-30 17:24

    console.log works.

    By default on iOS, it logs to the debug pane inside Xcode.

    From the IOS simulator press (+D) and press Remote JS Debugging. This will open a resource, http://localhost:8081/debugger-ui on localhost. From there use Chrome Developer tools javascript console to view console.log

    0 讨论(0)
  • 2020-11-30 17:25

    Use console.debug("text");

    You will see the logs inside the terminal.

    Steps:

    • Run the application:
    react-native run-ios        # For iOS
    react-native run-android    # For Android
    
    • Run the logger:
    react-native log-ios        # For iOS
    react-native log-android    # For Android
    
    0 讨论(0)
提交回复
热议问题