sree_iphonedev
sree_iphonedev

Reputation: 3534

React native error - expected a string or a class but got object

I am new to react-native. I was trying to write simple programs found from tutorials in order to familiar with react-native environment. I have researched on the same bug on stackoverflow itself and couldn't find any helpful solution, that's the reason I am writing again.

I was referring to the following tutorial

https://levelup.gitconnected.com/getting-started-with-react-native-in-2019-build-your-first-app-a41ebc0617e2

Following is the code that I have used. Created a new class named EmojiDict.js

import React, { Component } from 'react'
import { View, Text, StyleSheet } from 'react-native'

class EmojiDict extends Component {
state = {
    '😃': '😃 Smiley',
    '🚀': '🚀 Rocket',
    '⚛️': '⚛️ Atom Symbol'
};

render() {
    return (
        <View style={styles.container} >
            <Text>this.state['😃'] </Text>
        </View>
    );
  }
}

const styles = StyleSheet.create({
container: {
    flex: 1,
    justifyContent: 'center',
    alignItems: 'center',
    backgroundColor: '#F5FCFF'
},
instructions: {
    textAlign: 'center',
    color: '#333333',
    marginBottom: 5
  }
});

Then modified the App.js class as follows:

import React, { Component } from 'react';
import { Platform, StyleSheet, Text, View } from 'react-native';
import EmojiDict from './src/components/EmojiDict';

export default class App extends Component {
render() {
    return <EmojiDict />;
  }
}

I have tried various examples and nothing worked when the App.js class gets modified. I am not able to go forward due to this error.

Upvotes: 0

Views: 55

Answers (1)

Adarsh
Adarsh

Reputation: 2279

It's looks like you forgot to export the EmojiDict component

instead of class EmojiDict extends Component {

try

export default class EmojiDict extends Component {

may resolve this issue

Upvotes: 1

Related Questions