How can I view network requests (for debugging) in React Native?

前端 未结 12 1192
借酒劲吻你
借酒劲吻你 2020-11-28 03:16

I\'d like to view my network requests in React Native to help me debug - ideally in the \'Network\' tab of Chrome\'s devtools.

There are some closed issues about thi

12条回答
  •  盖世英雄少女心
    2020-11-28 03:39

    If you are looking to debug network requests on a release version of your app you can use the library react-native-network-logger. It lets you monitor and view network requests within the app from a custom debug screen.

    You can then put this behind a build flag or a network flag to disable it for users in the production app.

    Just install it with yarn add react-native-network-logger then add this at the entry point of your app:

    import { startNetworkLogging } from 'react-native-network-logger';
    
    startNetworkLogging();
    AppRegistry.registerComponent('App', () => App);
    

    And this on a debug screen:

    import NetworkLogger from 'react-native-network-logger';
    
    const MyScreen = () => ;
    

    Disclaimer: I'm the package author.

提交回复
热议问题