Hi Friends đź‘‹,

Welcome To Infinitbility! ❤️

To fix Invariant Violation: Element type is invalid: expected a string (for built-in components) or a class/function (for composite components) but got: object. You likely forgot to export your component from the file it's defined in. In this issue, You have to check your imported components and change as per exported in your project.

Today, I’m going to show how do I fix the element type is invalid expected a string in react native, here we will take two cases of this issue that cause this error.

  1. Issue caused by external components
  2. Issue caused by internal components

Here, we will learn to solve this issue based on their code.

Let’s start with Issue caused by external components

Issue caused by external components

Here, when you know this issue is caused by external components which you have imported into your project.

Then you have to Check

  1. Package path is correct or not
  2. If correct go to their code and then check for exporting their component they are using the default keyword or not.

For example.

I have imported the below package like this ( but this will work they are exported like export default WebView )

import WebView from 'react-native-webview-messaging/WebView';

But when I checked they are exporting this package like export WebView

so in this case we have to import like below.

import { WebView } from 'react-native-webview-messaging/WebView';

Issue caused by internal components

Here, when you know this issue is caused by internal components which you have created and imported into your project.

Then you have to Check

  1. imported path is correct or not.
  2. if correct check whether the component is exported or not.
  3. if exported check their syntax like the below example.

If you are able to see components exported with the default keyword.

then you import it like below

import ErrorMessage from '../Components/ErrorMessage';

Else

import {ErrorMessage} from '../Components/ErrorMessage';

I hope it’s help you, All the best 👍.