I'm trying to display my nav items using map inside my Navbar component but it's not working. I got the error as: "Cannot read properties of undefined (reading 'map')". I don't know what is wrong. Please help me. Thank you so much!
Navbar.js:
import React from "react";
import navItems from "./NavItems";
import { Link } from "react-router-dom";
function Navbar() {
return (
<div>
<ul>
{navItems.map((item) => {
return (
<li key={item.id} className={item.cName}>
<Link to={item.path}>{item.title}</Link>
</li>
);
})}
</ul>
</div>
);
}
export default Navbar;
NavItems.js:
export const navItems = [
{
id: 1,
title: "Home",
path: "./",
cName: "nav-item"
},
{
id: 2,
title: "Services",
path: "./services",
cName: "nav-item"
},
{
id: 3,
title: "Products",
path: "./products",
cName: "nav-item"
},
{
id: 4,
title: "Contact Us",
path: "./contactus",
cName: "nav-item"
}
];
Sanbox link: https://codesandbox.io/s/competent-agnesi-ho4h8?file=/src/components/NavItems.js:0-375