Vladimir
Vladimir

Reputation: 89

"Cannot read property createElement of "undefined"" error in react-native

I need your help. I created a standalone component, that I import in my main component. But when I trying to run my app I see an error "Cannot read property createElement of 'undefined'". Red arrow points on TouchableOpacity in my component. What is my problem? Thanks a lot

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

const MyButton = ({ name, onPress }) => {
    const { container, text } = styles;
    return (
        <TouchableOpacity onPress={onPress}>
            <View style={container}>
                <Text style={text}>{name}</Text>
            </View>
        </TouchableOpacity>
    )
}

const styles = StyleSheet.create({
    container: {
        width: 250,
        height: 30,
        backgroundColor: 'aqua',
        alignSelf: 'center'
    },

    text: {
        color: 'white',
        fontSize: 30
    }
})

export { MyButton }

Upvotes: 0

Views: 198

Answers (1)

Oriun
Oriun

Reputation: 244

You should import React this way : import React from 'react';

Upvotes: 2

Related Questions