question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Element type is invalid... Check the render type of `Icon`

See original GitHub issue

Getting Element type is invalid... Check the render type of 'Icon' when using <Avatar.Icon>

I am using a <Card>, of which I am trying to use a custom image as the .Left of the <Card.Title>, using a custom <Avatar.Icon> render function. My code is as follows:

<Card.Title
            title="Title goes here"
            subtitle="Created 14/3/19"
            left={(props) =>
              <Avatar.Icon {...props} icon={({ size, color }) => (
                <Image
                  source={{ uri: 'https://avatars0.githubusercontent.com/u/17571969?v=3&s=400' }}
                  style={{ width: size, height: size, tintColor: color }}
                />
              )} />
            }
/>

In case it makes a difference, my imports look like:

import React, {Component} from 'react';
import {Platform, StyleSheet, Text, View} from 'react-native';
import {Avatar, Button, Card, Title, Paragraph, IconButton, Image} from 'react-native-paper';

However, I get the following error:

Invariant Violation: Element type is invalid: expected a string (for built-in components) or a class/function (for composite components) but got: undefined. You likely forgot to export your component from the file it's defined in, or you might have mixed up default and named imports.

Check the render method of `Icon`.

This error is located at:
    in Icon (at AvatarIcon.js:80)
    in RCTView (at View.js:45)
    in View (at AvatarIcon.js:68)
    in Avatar.Icon (created by Context.Consumer)
    in ThemeProvider (created by Context.Consumer)
    in withTheme(Avatar.Icon) (at App.js:23)
    in RCTView (at View.js:45)
    in View (at CardTitle.js:110)
    in RCTView (at View.js:45)
    in View (at CardTitle.js:102)
    in Card.Title (created by Context.Consumer)

Why am I getting this error? How can I fix this? Also, if it would be easier, I would also be happy with any suggestions regarding alternative approaches to getting an image from a custom URI into the <Card.Title>.

Test URL

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:6 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
satya164commented, Jul 14, 2019

Seems to load fine for me. Though it’ll be white because you’re passing tintColor to the Image. You probably want to use Avatar.Image as mentioned in the docs: https://callstack.github.io/react-native-paper/avatar-image.html

0reactions
gezakerecsenyicommented, Jul 14, 2019

Thanks; that fixed it. 😃

Read more comments on GitHub >

github_iconTop Results From Across the Web

Error: Element type is invalid with Check the render method in ...
Error: Element type is invalid: expected a string (for built-in components) or a class/function (for composite components) but got: undefined.
Read more >
Element type is invalid... Check the render method of `Toggle`.
I keep getting Error: Element type is invalid... Check the render method ... icons/moon.svg'; import { ReactComponent as SunIcon } from '.
Read more >
(React) Element type is invalid, expected a string (for built in ...
To solve the error "Element type is invalid -- expected a string (for built-in components) or a class/function (for composite components) but got",...
Read more >
Error: Element type is invalid: expected a string-React Native
Coding example for the question Error: Element type is invalid: expected a string-React Native.
Read more >
Element type is invalid: expected a string (for built-in ...
Element type is invalid : expected a string (for built-in components) or a class/function (for composite components) but got: undefined. edit.js : /**...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found