首页 > 解决方案 > 反应原生的意外错误

问题描述

我是 react-native 的新手,正在创建一个学习演示。我在第 1 行遇到错误。我的 DataDetail 文件中的 11 DataDetail.js Unexpected token (11:2)。下面是我的 DataDetail 文件的代码。

1. //DataDetail.js
2. 
3. import React from 'react';
4. import {Text,View} from 'react-native';
5. 
6. const DataDetail = (props) => {
7.  return (
8.    <View>
9.      <Text>{props.objData.title}</Text>
10.    </View>>
11.  );
12. };
13. 
14. export default DataDetail;

我从我的组件中调用它:

import DataDetail from './DataDetail';
import React, {Component} from 'react';
import {Text,View} from 'react-native';
import axios from 'axios';

export default class Home extends Component<Props> {

state = {arrData:[]};

componentWillMount(){
  axios.get('https://reduxblog.herokuapp.com/api/posts')
  .then(response => this.setState({arrData:response.data}));
}

renderList(){
  return this.state.arrData.map(data => <DataDetail key={data.id} objData={data} />);
}

render() {
  return (
    <View>
      {this.renderList()}
    </View>
  );
}
}

任何人都可以在这里帮助我理解,我在这里做错了什么。

谢谢

标签: javascriptreact-native

解决方案


>关闭View标签时您有 2 个。

6. const DataDetail = (props) => {
7.  return (
8.    <View>
9.      <Text>{props.objData.title}</Text>
10.    </View>
11.  );
12. };

推荐阅读