[英]React Native: Create component error
I am trying to create a react native component, basically just re-rendering the default screen via a component. 我试图创建一个react native组件,基本上只是通过一个组件重新渲染默认屏幕。 But I am getting an error:
但我收到一个错误:
Cant find variable: Component
Login.js: Login.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: 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 );
Component it cannot find is <Login />
. 它找不到的组件是
<Login />
。
I have looked at the movies example in the official repo, as well as a couple of other examples, and I cant see what I am doing wrong/differently. 我看了官方回购中的电影示例,以及其他几个示例,但看不到自己做错了什么/与众不同。
I am on windows 10, both index.android.js and login.js are in the root directory (neither in sub dirs). 我在Windows 10上,index.android.js和login.js都在根目录中(都不在子目录中)。
You forgot to include the Component class from React. 您忘记了包含React的Component类。
var {
AppRegistry,
Component,
} = React;
OR 要么
class fortysevenui extends React.Component {
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.