Hi, I am learning to code in typescript with react. I have no background in this domain, I am coming from python programming in robotics. I am sure this is a really easy solve, but I am simply lost, there's a lot of new stuff here 😅
With this in mind, I was trying to developp a user interface to control a simulation. I am at the very early stage of setting up the menu. I wanted to use tabs for this. My goal was that each tab would redirect to another page, in order to make code more separate and clean, but I'm having trouble using hooks with router.
My TabMenu.tsx files looks like this:
import { useState } from "react";
import { useNavigate } from "react-router-dom";
interface TopMenuProps {
tabName: string[];
}
var navigate = useNavigate();
const routeChange = (item: string) => {
let path: string;
if (item === "Home") {
path = "page";
} else {
path = "./" + item + "/page";
}
navigate(path);
};
const TopMenu = ({ tabName }: TopMenuProps) => {
const [selectedMenu, setSelectedMenu] = useState(-1);
return (
<div role="tablist" className="tabs tabs-lifted">
{tabName.map((item, index) => (
<a
role="tab"
className={
selectedMenu === index
? "tab tab-active [--tab-bg:lightblue] [--tab-border-color:blue]"
: "tab"
}
key={item}
onClick={() => {
setSelectedMenu(index);
routeChange(item);
}}
>
{item}
</a>
))}
</div>
);
};
export default TopMenu;
And my main page.tsx looks like this
"use client";
import TopMenu from "./components/TopMenu";
import React, { useState } from "react";
var menu = ["Home", "Simulation", "Parameter"];
function App() {
return (
<div>
<TopMenu tabName={menu} />
</div>
);
}
export default App;
I am using React with Next.js, using daisyUI
My error is shown in the picture.