当我尝试使用我创建的loginPage组件时,我得到了一个组件类得到了对象错误。
这里是index.ios.js
import React, {Component} from 'react';
import {
AppRegistry,
View
} from 'react-native';
import loginPage from './pages/loginPage'
class app extends Component {
render() {
return (
<View>
<loginPage/>
</View>
);
}
}
AppRegistry.registerComponent('app', () => app);
这是loginPage.js
import React, { Component } from 'react';
import {
StyleSheet,
Text,
View
} from 'react-native';
export default class loginPage extends Component {
render() {
return (
<View>
<Text>
Welcome to React Native!
</Text>
</View>
);
}
}
答案 0 :(得分:97)
您需要将loginPage
课程重命名为LoginPage
,该课程必须大写
答案 1 :(得分:4)
<强> loginPage.js 强>
import React, {Component} from 'react';
import {
AppRegistry,
View
} from 'react-native';
import LoginPage from './pages/loginPage'
class app extends Component {
render() {
return (
<View>
<LoginPage/>
</View>
);
}
}
<强> index.ios.js 强>
{{1}}
答案 2 :(得分:0)
删除index.ios.js
import React, {Component} from 'react';
import {
AppRegistry,
View
} from 'react-native';
import loginPage from './pages/loginPage'
class app extends Component {
render() {
return (
<loginPage/>
);
}
}
AppRegistry.registerComponent('app', () => app);