元素类型无效,预期字符串未定义

时间:2016-07-18 14:01:28

标签: javascript react-native

所以我正在学习React Native的课程,似乎有点过时了。 只是尝试导入单个组件。

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

class AwesomeProject extends Component {
  constructor(props, context) {
      super(props, context);
      this.state = {
        todos:[
          {
            task:'Learn React Native'
          },
        ],
      };
  }

  render() {
    return (
      <TaskList />
    );
  }
}

AppRegistry.registerComponent('AwesomeProject', () => AwesomeProject);

TaskList.js

import React, { Component } from 'react';

const {
    Text,
} = React;

class TaskList extends Component {
  render() {
    return (
      <Text>Hi this is the TaskList!</Text>
    );
  }
}

export default TaskList;

我环顾四周,其他地方我没有做错

1 个答案:

答案 0 :(得分:8)

应从Text导入

react-native。在TaskList尝试做

 import { 
   Text, 
 } from 'react-native' 

而不是

 const {
   Text,
 } = React;