Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

react native - expected a component class, got [object Object]

I got expected a component class got object error when I try to use loginPage component which I created.

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

and here is the 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>
        );
    }
}
like image 384
Emre Tekince Avatar asked Jun 26 '16 13:06

Emre Tekince


2 Answers

You need to rename your loginPage class to LoginPage, the class must be capitalize

like image 60
fandro Avatar answered Oct 18 '22 12:10

fandro


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>
        );
    }
}
like image 39
ayoub laaziz Avatar answered Oct 18 '22 10:10

ayoub laaziz