Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

React Js Components imported but not displaying

I have two components ‘footer’ and ‘header’ in the components directory. It imports properly but I am not able to display it.

App.js

import header from "./components/header";
import footer from "./components/footer";

function App() {
 
  return (

    <>
      <header />
      <main>
          <h1>Welcome to Proshop</h1>
      </main>
      <footer />
    </>
  )
}

export default App;

header.js

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

import React from 'react'

function header() {
  return (
    <div>header</div>
  )
}

export default header

footer.js

import React from 'react'

function footer() {
  return (
    <div>footer</div>
  )
}

export default footer

The output is just this

enter image description here

>Solution :

Your components must start with a capital letter, if not they will be treated like a regular html tags, see the docs on this

When an element type starts with a lowercase letter, it refers to a built-in component like or and results in a string ‘div’ or ‘span’ passed to React.createElement. Types that start with a capital letter like compile to React.createElement(Foo) and correspond to a component defined or imported in your JavaScript file.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading