Skip to content
Advertisement

React Element Type is Invalid, why am I getting this error and how do I solve it?

I get the following error when trying to run my react site:

“Error: 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 Home.”

After reviewing [this] React.createElement: type is invalid — expected a string and [this]Check the render method I still am lost in how to fix the problem. Here is a screenshot of the console enter image description here

Code: Index.js

JavaScript

App.js

JavaScript

Home.js

JavaScript

Advertisement

Answer

When getting started with ReactJS programming, it is common that junior developers write mistakes and break the rendering.

Most of the time, check their component sources exports (named/default), check their integration and simplify their render method.

The best way to do is to fix the rendering until you find the breaking point :

  1. remove code from components
  2. reduce the amount of rendered components

The more you clean your code and simplify it, the easiest it will be to get a successful render.

This will help you locate the bad component and fix it. When you are done, just use git revert and apply your fix.

Advertisement