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,583
  • 5
  • 17
  • 29

3 Answers3

96

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

fandro
  • 4,551
  • 7
  • 37
  • 59
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
  • 10,376
  • 4
  • 57
  • 65
ayoub laaziz
  • 988
  • 8
  • 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
  • 1,930
  • 22
  • 29
  • 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