1

I was just learning React fundamentals and then I got this problem:

Error: 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, or you might have mixed up default and named imports. Check the render method of App.

I looked at everything and I don't know if I got something wrong there because I can't see any errors at all. Saw some problems like this but couldn't solve my own one :D here is some code

index.js:

import React from 'react';
import ReactDOM from 'react-dom';
import App from './App';


ReactDOM.render(<App />,document.getElementById('root'));

app.js:

import React from "react";
import Footer from "./components/Footer";
import MainContent from "./components/MainContent";
import Navbar from "./components/Navbar";

function App() {
  return (
    <div>
      <Navbar />
      <MainContent />
      <Footer />
    </div>
  )
}


export default App

Navbar.js:

import React from 'react';

function Navbar() {
    return (
        <nav>This is a Navbar</nav>
    )
}

export default Navbar

MainContent.js:

import React from 'react';

function MainContent() {
    return (
        <main>This is a footer</main>
    )
}

export default MainContent

Footer.js:

import React from 'react';

function Footer() {
    return (
        <footer>This is a footer</footer>
    )
}

export default Footer
Brian Thompson
  • 13,263
  • 4
  • 23
  • 43
uski9992
  • 21
  • 1
  • 5

2 Answers2

0

is it because you're importing from the file App.js (capitalized) but the file is called app.js (no caps) ?

azium
  • 20,056
  • 7
  • 57
  • 79
  • If this is the issue, we should put a comment and mark it as a Typographical question. Your point maybe valid but is does not answer anything. Its more of a comment at this point of time – Rajesh Nov 18 '20 at 14:49
  • It seems very unlikely since the error says "check the render method of App". That would make it seem like `App` is imported and used correctly, but one of it's children is not. – Brian Thompson Nov 18 '20 at 15:09
  • This does not provide an answer to the question. To critique or request clarification from an author, leave a comment below their post. - [From Review](/review/low-quality-posts/27648558) – Dragonthoughts Nov 18 '20 at 15:09
  • @BrianThompson yeah I thought that as well, but it wouldn't surprise me if this was indeed the issue--my original suggestion was to rebuild everything, maybe something got stuck while code changes were being made – azium Nov 18 '20 at 15:14
  • @Dragonthoughts I believe this could be the answer, so I'm sticking to my guns here. – azium Nov 18 '20 at 15:14
  • The OP's code works in codesandbox: https://codesandbox.io/s/blissful-bush-qkbi8?fontsize=14&hidenavigation=1&theme=dark (minus changing MainContent render text content to match), so I agree with the answer that this is a typo somewhere. – AnilRedshift Nov 24 '20 at 17:52
0

This may not be the issue: but have you tried changing <footer>, <nav>, and <main> to just <div>?

Jon
  • 622
  • 8
  • 29