反应原生 - 期望一个组件类,得到[object Object]

时间:2016-06-26 13:03:04

标签: javascript reactjs react-native

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

3 个答案:

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