反应本地 – 预期一个组件类,得到

当我尝试使用我创build的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> ); } } 

您需要将loginPage类重命名为LoginPage ,该类必须大写

loginPage.js

 import React from 'react'; import { Text, View } from 'react-native'; const LoginPage = () => { return ( <View> <Text> Welcome to React Native! </Text> </View> ); } export default 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> ); } } 

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