React Native应用程序崩溃

时间:2017-09-19 04:53:51

标签: react-native

该应用程序有一个名为Home的页面,这是home的代码。当应用程序运行时,它 崩溃。请找到可能的错误并尝试解决此源代码上的问题。 注意:我们假设API响应为200,数据没有任何问题。

import React, { Component, } from ‘react’ ;
import { View, Text } from ‘react-native’ ;
import PropTypes from 'prop-types' ;
import Api from ‘../../utils/api’ ;
import * as styles from ‘../../styles/styles’ ;

class HomeView extends Component {
    constructor (props) {
        super(props);
        this .state = { data: null };
    }

    render () {
        Api. fetchData ( this .props.name, this .props.phoneNumber)
            . then (response => {
                self .setState({data: response.data});
                self.props.onUpdate({ data: response.data});
        });
        return (
            < View style={style.container}>
                < Text style={style.row}>
                    {this.state.data.fullName}
                </ Text >
                < Text style={style.row}>
                    {this.state.data.phoneNumber}
                </ Text >
                < Text style={style.row}>
                    {this.state.data.maritalStatus}
                </ Text >
            </ View >
        )
    }
}

const style = styles.homeView;
HomeView. propTypes = {
    name: PropTypes .string,
    phoneNumber: PropTypes .string,
}
HomeView. defaultProps = {
    name: 'Aliens',
    phoneNumber: '+999999999',
}

1 个答案:

答案 0 :(得分:0)

请删除Api. fetchData

中的空格
Api.fetchData ( this.props.name, this.props.phoneNumber)
  .then (response => {
  self.setState({data: response.data});
  self.props.onUpdate({ data: response.data});
});