如何在React Native中显示错误?

时间:2017-10-15 07:47:29

标签: react-native

我正在学习本机反应,所以当程序崩溃时,它只显示15:31:42: Failed building JavaScript bundle所说的全部内容。那么我可以使用任何文件或工具来查找更多细节错误,如Eclipse或dotCMS日志文件或我的代码行有语法错误?

3 个答案:

答案 0 :(得分:1)

希望此示例将为您提供帮助。

    import React, { Component } from 'react';
    import { StyleSheet, View, Text } from 'react-native';

    export default class App extends Component {
      state = {
             items: [],
             errorMessage : 'Server Error!'//You have to set this message depends on your server response
             }

      render() {
        return (
          <View style={styles.MainContainer}>
            <Text style={{ fontSize: 23 }}> { this.state.errorMessage } </Text>
          </View>
        );
      }
    }

    const styles = StyleSheet.create({
      MainContainer: {
        flex: 1,
        paddingTop: 20,
        alignItems: 'center',
        marginTop: 50,
        justifyContent: 'center'
      }
    });

答案 1 :(得分:0)

对于开发,只需在启用远程调试时使用console.log和debug。对于制作,您可以使用Fabric,我喜欢它。有关调试follow the docs

的更多信息

答案 2 :(得分:0)

您可以使用Chrome开发者工具。

首先在模拟器中打开开发人员工具。然后按Command + D键盘快捷键。它将打开开发人员工具。

要在Chrome中调试JavaScript代码,请从“开发人员”菜单中选择“远程调试JS”。这将在http://localhost:8081/debugger-ui打开一个新标签。

然后你可以在chrome浏览器上使用“Inspect Element”。然后你可以选择控制台。

如果应用中出现问题,您可以在Google Chrome浏览器中通过控制台进行跟踪。

http://facebook.github.io/react-native/releases/0.49/docs/debugging.html#chrome-developer-tools