React Native:创建组件错误

React Native: Create component error

本文关键字:组件 错误 创建组 创建 Native React      更新时间:2023-09-26

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

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 );

它找不到的组件是<Login />

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

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

你忘了包含来自 React 的 Component 类。

var {
  AppRegistry,
  Component,
} = React;

class fortysevenui extends React.Component {