Skip to content

Commit

Permalink
Solved Nav Bug
Browse files Browse the repository at this point in the history
  • Loading branch information
vwakesahu committed Mar 27, 2024
1 parent 7b076b5 commit 524fb73
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 5 deletions.
2 changes: 1 addition & 1 deletion .env.sample
Original file line number Diff line number Diff line change
@@ -1 +1 @@
API_URL=
API_URL=https://www.google.com
18 changes: 14 additions & 4 deletions src/components/nav/main-nav.js
Original file line number Diff line number Diff line change
@@ -1,17 +1,27 @@
"use client";
import React, { useState } from "react";
import React, { useEffect, useState } from "react";
import Link from "next/link";

import { siteConfig } from "@/config/site";
import { cn } from "@/lib/utils";
import { Icons } from "./icons";
import { usePathname } from "next/navigation";

function MainNav({ items }) {
const [activeIndex, setActiveIndex] = useState(0);
const pathname = usePathname();




useEffect(() => {
const foundIndex = items.findIndex((item) => item.href === pathname);
// console.log(foundIndex)
if (foundIndex !== -1) {
setActiveIndex(foundIndex);
}
}, [])

const handleLinkClick = (index) => {
setActiveIndex(index);
};

return (
<div className="flex gap-6 md:gap-10">
Expand Down

0 comments on commit 524fb73

Please sign in to comment.