I am not able to import function Navbar, I get a blank output but if I try to build the function in file.js it works so there should be error in how I import it. Any advice? in Here are my 3 files:
navbar.js
export default function Navbar(){
return<nav className="Navbar">
<a href="/" className="site-title">
Hello name of the site
</a>
<ul>
<li>
<a href="/pricing_option1">Pricing_option1</a>
<a href="/pricing_option2">pricing_option2</a>
</li>
</ul>
</nav>
}
index.html
<html>
<head>
<link rel="stylsheet" href="index.css">
<script crossorigin src="https://unpkg.com/react@18/umd/react.development.js"></script>
<script crossorigin src="https://unpkg.com/react-dom@18/umd/react-dom.development.js"></script>
<script src="https://unpkg.com/babel-standalone@6/babel.min.js"></script>
</head>
<body>
<div id="root"></div>
<script src="file.js" type="text/babel" ></script>
</body>
</html>
file.js
import Navbar from "./navbar"
ReactDOM.render(<div>
<Navbar />
</div>, document.getElementById("root"))
Output: blank
if I try to build the function in file.js it works so there should be error in how I import it.
2
Answers
NavBar.js:
index.html:
file.js:
Try this:
Delete export default function Navbar
Insert export default Navbar; on the bottom of your file.