IN header.js
function header(){
return(<div className="header"><header><h1>Header Content</h1></header></div>);
}
export default header;
IN footer.js
function footer(){
return(<div className="footer"><footer>copyright 2022-23</footer></div>)
}
export default footer;
**IN App.js**
import React from 'react';
import header from './header';
import footer from './footer';
function App() {
return (
<div>
<div><header/></div>
<div><footer/></div>
</div>
);
}
export default App;
**why the import functions are not working?**
please correct my code I want to display the content of header.js and footer.js file in App.js but it is saying that the header and footer variables are unused in App.js file.
3
Answers
In JSX, components must start with a capital letter. When you are using the
<header />
and<footer />
tags, they are being interpreted as those html elements. To fix it, rename yourheader
andfooter
components toHeader
andFooter
respectively.In React Component names should be written with Capital letters
Header Component
Footer Component
App Component
When you’re importing components, you need to capitalize the component names because React treats lowercase names as regular HTML elements.
Rename your components :
replace in your code :
Finally, use Header and Footer in your app.js
For more clear please have a look at HTML header and
User Defined Components Must Be Capitalized