ViktorG
ViktorG

Reputation: 515

Element type is invalid: expected a string (for built-in components)

I have a problem with the react-native buttons. When I test them in a newly initialized project, everything works fine. But when I want to implement them into my project, it does not work and it gives me an error...

This here is a part of my project (not important stuff has been left out):

import React from 'react';
import {
  Platform,
  StyleSheet,
  TouchableOpacity,
  View,
  Image,
  Text,
  Button,
  Alert
} from 'react-native';

export default class CustomButtons extends React.Component {

  constructor(props) {
    super(props);
  }

  
onPressLearnMore(){
  Alert.alert("WORKING");
}

  render(){
    return(
      <Button
        onPress={this.onPressLearnMore()}
        title="Learn More"
        color="#841584"
        accessibilityLabel="Learn more about this purple button"
      />
    );
  }
}

This is the error: enter image description here

I´ve been reading about solutions, where the import of the Button was not correct, I don't see anything wrong with mine though. An help would be great!

Upvotes: 1

Views: 1319

Answers (1)

jevakallio
jevakallio

Reputation: 35890

The Button component was added to React Native 0.37. You are probably using an older version.

Upvotes: 2

Related Questions