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

How to Import Component in React JS

I am trying to import Header Component in App.js
but it’s giving error.

import './App.css';
import Headers from './Components/Header';

function App() {
  return (
    <div>
    </Headers>
    </div>
  );
}

export default App;

Header.js

import React from "react";

export default function Headers(){
 
    return (
        <div>
        Header Demo
        </div>
    );
    
}

Header.js file exist in src/Components

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

Compiled with problems:X

ERROR in ./src/App.js

Module build failed (from ./node_modules/babel-loader/lib/index.js):
SyntaxError: /home/sanad/Documents/newapp/src/App.js: Expected corresponding JSX closing tag for . (8:4)

>Solution :

Your problem has nothing to do with importing the module.

Read the error message carefully:

SyntaxError: /home/sanad/Documents/newapp/src/App.js: Expected corresponding JSX closing tag for <div>.

This is because you have a closing tag (</Headers>) but the next element that needs to be closed in <div>.

Your problem is that you need to open the <Headers> element first.

<div>
    <Headers></Headers>
</div>
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