seenu27jidhin / react-project-sample

This project react with typescript. Included pages,menubar and footer
0 stars 0 forks source link

navbar menu dynamic #1

Open seenu27jidhin opened 3 months ago

seenu27jidhin commented 3 months ago

i am trying to do a dynamic menubar with id, label and link .but i got an error like

"Property 'id' does not exist on type '{ id: number; } | { label: string; } | { link: string; }'".

here is my code

in navbar.tsx

import { useState } from "react"; import "../App.css" interface NavBarProps { brandName: string; imageSrcPath: string; navItems: [{id:number},{label:string},{link:string}];

} function NavBar({ brandName, imageSrcPath, navItems }: NavBarProps) { const [selectedIndex, setSelectedIndex] = useState(-1);

return (

); }

export default NavBar;

in app.tsx

function App() { const items = [ { id:1, label:"Home",link:'/' }, {id:2, label:"Product",link:'/product'}, {id:3,label:"Contact",link:'/contact'}, ]; return (

) }

export default App

can you help me to figure out this problem.?

seenu27jidhin commented 3 months ago

i fixed that problem

in navbar.tsx

interface ItemList { id:number; label:string; link:string } interface NavBarProps { brandName: string; imageSrcPath: string; navItems: ItemList[]; }