39

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>
        );
    }
}
Emre Tekince
  • 1,723
  • 5
  • 18
  • 30

3 Answers3

96

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

fandro
  • 4,833
  • 7
  • 41
  • 62
4

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>
        );
    }
}
Pylinux
  • 11,278
  • 4
  • 60
  • 67
ayoub laaziz
  • 1,196
  • 9
  • 12
0

remove the tags in 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);
Sebastianb
  • 2,020
  • 22
  • 31
  • Well, I somehow cannot edit this because the edit is less than 6 characters (thanks SO) but the `` tags you are reffering to are not rendering. – ArchNoob Jul 04 '17 at 03:01