react-native-vector-icons icon indicating copy to clipboard operation
react-native-vector-icons copied to clipboard

Invariant Violation: Element type is invalid: expected a string (for built-in components) or a class/function (for composite components) but got: undefined

Open hugoskn opened this issue 5 years ago • 9 comments

Im getting error: "Invariant Violation: Element type is invalid: expected a string (for built-in components) or a class/function (for composite components) but got: undefined". I'm using react-native-vector-icons/FontAwesome": "6.1.0". With Expo SDK 31.0.0 and 32.0.0.

I add the reference at the top like: "import {Icon} from 'react-native-vector-icons/FontAwesome';" And then I try to add a simple icon like: <Icon name='envelope' color='black' /> but I got the error mentioned.

Reproducible Demo https://snack.expo.io/@hugoskn/iconerror

hugoskn avatar Jan 14 '19 22:01 hugoskn

I'm getting this error as well, here's my code

import React from 'react';
import { TabBarIOS, Text } from 'react-native';
import Icon from 'react-native-vector-icons/Ionicons';

export default class Container extends React.Component {
	constructor(props) {
		super(props);
		this.state = { tab: 'home' };
	}
	render() {
		return (
			<TabBarIOS>
				<Icon.TabBarItemIOS
					title="Home"
					iconName="ios-home"
					selected={this.state.tab === 'home'}
					onPress={() => this.setState({ tab: 'home' })}>
					<Text>Home</Text>
				</Icon.TabBarItemIOS>
				<Icon.TabBarItemIOS
					title="Outline"
					iconName="ios-checkbox"
					selected={this.state.tab === 'checkbox'}
					onPress={() => this.setState({ tab: 'checkbox' })}>
					<Text>Outline</Text>
				</Icon.TabBarItemIOS>
			</TabBarIOS>
		);
	}
}

I should note that using <Icon> outside of TabBarIOS works fine, just Icon.TabBarItemIOS fails

kufii avatar Jan 22 '19 02:01 kufii

@hugoskn I had the same issue and didnt find a solution for react-native-vector-icons. What I did instead was using Expo's icons by adding code below. You may also think about doing the same if you are using Expo.

import { FontAwesome } from '@expo/vector-icons';
<FontAwesome name='envelope' color='black' />

sinansonmez avatar Jan 25 '19 14:01 sinansonmez

I am getting the same error, did you find the solution without using the expo icons?

garucin27 avatar Jan 25 '19 17:01 garucin27

`import React from "react"; import { View, Text, StyleSheet, Platform } from "react-native"; import {withNavigation} from 'react-navigation' import Icon from 'react-native-vector-icons';

const ShoppingCartIcon = (props) => ( <View style={[{ padding: 5 }, Platform.OS == 'android' ? styles.iconContainer : null]}>

    <Text style={{ color: 'red', fontWeight: 'bold' }}>Text</Text>

<Icon onPress={() => this.props.navigation.navigate('Cart')} name="ios-cart" size={30} />
) export default withNavigation(ShoppingCartIcon);

const styles = StyleSheet.create({ container: { flex: 1, alignItems: 'center', justifyContent: 'center' }, iconContainer: { paddingLeft: 20, paddingTop: 10, marginRight: 5 } });`

can anyone help me with this? I am using: "react-native-vector-icons": "^6.6.0", "react-native": "0.61.5",

sfs-atul avatar Jan 10 '20 12:01 sfs-atul

I'm getting this error as well, here's my code

import React from 'react';
import { TabBarIOS, Text } from 'react-native';
import Icon from 'react-native-vector-icons/Ionicons';

export default class Container extends React.Component {
	constructor(props) {
		super(props);
		this.state = { tab: 'home' };
	}
	render() {
		return (
			<TabBarIOS>
				<Icon.TabBarItemIOS
					title="Home"
					iconName="ios-home"
					selected={this.state.tab === 'home'}
					onPress={() => this.setState({ tab: 'home' })}>
					<Text>Home</Text>
				</Icon.TabBarItemIOS>
				<Icon.TabBarItemIOS
					title="Outline"
					iconName="ios-checkbox"
					selected={this.state.tab === 'checkbox'}
					onPress={() => this.setState({ tab: 'checkbox' })}>
					<Text>Outline</Text>
				</Icon.TabBarItemIOS>
			</TabBarIOS>
		);
	}
}

I should note that using outside of TabBarIOS works fine, just Icon.TabBarItemIOS fails

did you find any solution?

sfs-atul avatar Jan 10 '20 12:01 sfs-atul

I have the same issue:

import { Icon } from 'react-native-vector-icons/FontAwesome'

    render() {
        return (
        <View style={styles.container}>
            <Searchbar
                style={styles.searchBar}
                ref={ref=>this.searchBar = ref}
                placeholder={this.props.route.params.categoryTitle}
                onChangeText={this.onChangeTextSearchBar}
                onIconPress={this.onSearchIconPress}
                value={this.state.searchQuery}
                />
            <Icon name='sort' size={30} color="#900" />
            <ScrollView>
                {this.state.dishes}
            </ScrollView>
        </View>
        )
    }

thachhuynh95 avatar May 03 '20 10:05 thachhuynh95

I have the same issue:

import { Icon } from 'react-native-vector-icons/FontAwesome'

    render() {
        return (
        <View style={styles.container}>
            <Searchbar
                style={styles.searchBar}
                ref={ref=>this.searchBar = ref}
                placeholder={this.props.route.params.categoryTitle}
                onChangeText={this.onChangeTextSearchBar}
                onIconPress={this.onSearchIconPress}
                value={this.state.searchQuery}
                />
            <Icon name='sort' size={30} color="#900" />
            <ScrollView>
                {this.state.dishes}
            </ScrollView>
        </View>
        )
    }

try using style={{height:30,width:30}} in place of size={30}

raazatul7 avatar May 04 '20 06:05 raazatul7

Same issue with FontAwesome5, I have tried importing as Icon and as FontAwesome5

jthoward64 avatar Nov 23 '21 16:11 jthoward64

I resolved this issue by importing like this: import Icon from "react-native-vector-icons/MaterialIcons"; instead of like this: import { Icon } from "react-native-vector-icons/MaterialIcons";

Quartzic avatar Jul 20 '22 14:07 Quartzic