【问题标题】:React Native: Create component errorReact Native:创建组件错误
【发布时间】:2016-02-20 19:55:00
【问题描述】:

我正在尝试创建一个反应原生组件,基本上只是通过一个组件重新渲染默认屏幕。但我收到一个错误:

Cant find variable: Component

登录.js:

    'use strict';
    var React = require('react-native');
    var {
      AppRegistry,
      Component,
      StyleSheet,
      Text,
      View
    } = React;

    var SearchScreen = React.createClass({

      getInitialState: function() {
        return {
        };
      },
      render: function() {
        return (
          <View style={styles.container}>
            <Text style={styles.welcome}>
              Welcome to React Native!
            </Text>
            <Text style={styles.instructions}>
              To get started, edit index.android.js
            </Text>
            <Text style={styles.instructions}>
              Shake or press menu button for dev menu
            </Text>
          </View>
        );
    }
    });


    const styles = StyleSheet.create({
      container: {
        flex: 1,
        justifyContent: 'center',
        alignItems: 'center',
        backgroundColor: '#F5FCFF',
      },
      welcome: {
        fontSize: 20,
        textAlign: 'center',
        margin: 10,
      },
      instructions: {
        textAlign: 'center',
        color: '#333333',
        marginBottom: 5,
      },
    });

module.exports = Login;

index.android.js:

/**
 * Sample React Native App
 * https://github.com/facebook/react-native
 */
'use strict';
var React = require('react-native');
var {
  AppRegistry
} = React;

var Login = require('./Login');

class theUI extends Component {
  render() {
    return (
      <Login />
    );
  }
}

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

找不到的组件是&lt;Login /&gt;

我查看了官方 repo 中的电影示例以及其他几个示例,但我看不出我做错了什么/有什么不同。

我在 Windows 10 上,index.android.js 和 login.js 都在根目录中(不在子目录中)。

【问题讨论】:

    标签: javascript android mobile reactjs react-native


    【解决方案1】:

    您忘记包含 React 中的 Component 类。

    var {
      AppRegistry,
      Component,
    } = React;
    

    class fortysevenui extends React.Component {
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-03-04
      • 1970-01-01
      • 1970-01-01
      • 2017-09-04
      • 2017-12-30
      • 2020-10-19
      • 2021-04-03
      • 2016-01-26
      相关资源
      最近更新 更多