0

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.

1 Answer 1

1

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

Sign up to request clarification or add additional context in comments.

3 Comments

Thanks Adarsh. That resolved the issue and would like to clarify that export default has to be used with all the classes defining.
yes, we need to exoprt a class component in-order to use it in other components, please refer : developer.mozilla.org/en-US/docs/web/javascript/reference/…
Thanks a lot Adarsh for the reference.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.