Build a Reusable Mega Navbar - Step 1

Tell us what’s happening:

Creating a component and exporting it but it is not passing the test. Ive also tried “export default function Navbar() {
return ();
};”
but I am not sure whats going on. I am new to react.

Your code so far

<!-- file: index.html -->
<!doctype html>
<html>
  <head>
    <meta charset="UTF-8" />
    <title>Hello World</title>
    <script src="https://unpkg.com/react@18/umd/react.development.js"></script>
    <script src="https://unpkg.com/react-dom@18/umd/react-dom.development.js"></script>

    <script src="https://unpkg.com/@babel/standalone/babel.min.js"></script>
    <script
      data-plugins="transform-modules-umd"
      type="text/babel"
      src="index.jsx"
    ></script>
     <link rel="stylesheet" href="./styles.css" />
  </head>
  <body>
    <div id="root"></div>
    <script
      data-plugins="transform-modules-umd"
      type="text/babel"
      data-presets="react"
      data-type="module"
    >
      import { Navbar } from './index.jsx';
      ReactDOM.createRoot(document.getElementById('root')).render(
        <Navbar />
      );
    </script>
  </body>
</html>
/* file: styles.css */
*,
*::before,
*::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

:root {
  --white: #fff;
  --light-grey: #e1e0e0;
  --dark-purple: #7c0e7c;
  --black: #000;
}

body {
  background-color: var(--light-grey);
}

.navbar {
  background-color: var(--white);
}

.navbar ul {
  display: flex;
  justify-content: space-around;
}

.navbar ul li {
  list-style: none;
  border-radius: 4px;
}

.navbar ul li a {
  text-decoration: none;
  color: var(--black);
  padding: 10px;
  display: inline-block;
  width: 100%;
}

button {
  background: transparent;
  border: none;
  font-family: 'Times New Roman', Times, serif;
  padding: 10px;
  font-size: 1rem;
}

.navbar ul .nav-item a:hover {
  background-color: var(--dark-purple);
  color: var(--white);
}

button:hover {
  background-color: var(--dark-purple);
  color: var(--white);
}

.navbar ul .nav-item .sub-menu {
  visibility: hidden;
  opacity: 0;
  position: absolute;
  right: 5%;
  transition: opacity 0.5s ease;
  display: block;
  background-color: var(--white);
}

@media (min-width: 768px) {
  .navbar ul .nav-item .sub-menu {
    right: 15%;
  }
}

@media (min-width: 1024px) {
  .navbar ul .nav-item .sub-menu {
    right: 13%;
  }
}

.navbar ul .nav-item:hover .sub-menu,
.navbar ul .nav-item:focus-within .sub-menu {
  visibility: visible;
  opacity: 1;
}
/* file: index.jsx */

{/* User Editable Region */}

function Navbar() {
  return ();
}

export default Navbar;

{/* User Editable Region */}

Your browser information:

User Agent is: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/133.0.0.0 Safari/537.36

Challenge Information:

Build a Reusable Mega Navbar - Step 1

you are returning “default export” try using “named export”

  • remove default export
  • add named export

address those changes and it should be fine, happy coding :slight_smile:

Take a look at this post:

https://forum.freecodecamp.org/t/build-a-reusable-mega-navbar-step-1/728979

The type of export really should be part of the requirement, unless you are meant to deduce it as part of the learning. Also, more importantly, I can’t find where named exports are taught?

If named exports are not taught (or I just can’t find it) and then the first workshop uses it, that would be an oversight/bug.


When you see brackets {} around the component import, it is a named export.

import { Navbar } from './index.jsx';

If it was a default export, it would be:

import Navbar from './index.jsx';

I opened an issue for it. But again, maybe I just missed it.

1 Like

I thought the same thing when I saw this post.

There is coverage for imports and exports in the JavaScript area and in the React area of the Full Stack curriculum, but I didn’t see any mention of named exports in the transcripts. Several students have tripped up on this step.

1 Like