添加按钮时元素类型无效

时间:2016-11-09 07:47:08

标签: react-native

我正在关注React Native基础教程。然后,在我结束之后,我尝试在TextInput tutorial中使用的代码中添加一个按钮,以下示例Button page

import React, { Component } from 'react';
import { AppRegistry, Text, TextInput, Button, View } from 'react-native';

class AwsumProjek extends Component {
    constructor(props) {
        super(props);
        this.state = {tiText: ''};
    }

    render() {
        return (
           <View style={{padding: 10}}>
              <TextInput
                style={{height: 40}}
                placeholder="Type here to translate!"
                onChangeText={(tiText) => this.setState({tiText})}
              />
              <Text style={{padding: 10, fontSize: 42}}>
                {this.state.tiText.split(' ').map((word) => word && 'WA').join(' ')}
              </Text>
              <Button
                title="Press Purple"
                color="#841584"
                accessibilityLabel="Learn more about purple"
              />
           </View>
        );
      }
    }

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

相反,我得到了这个错误

Element type is invalid: expected a string (for built-in components)
or a class/function (for composite components) but got: undefined. 
Check the render method of 'AwsumProjek'.

我做错了什么?看到其他答案,是否与导入内容有关?

我是本地Android开发人员,正在尝试学习React Native,就像我现在一样,Javascript对我来说完全不熟悉。

1 个答案:

答案 0 :(得分:0)

确保您使用的是正确版本的React Native。 Button组件是在React Native版本0.37中引入的