Skip to content

Cannot style the active menu item on Next.js #630

Answered by njncalub
njncalub asked this question in Help
Discussion options

You must be logged in to vote

Refined my search filters and found this: #145.

I've updated nikosolihin's comment for TypeScript and it's now working.

interface LinkWrapperProps {
  active: boolean;
  href: string;
  children?: React.ReactNode;
}

const LinkWrapper = React.forwardRef<HTMLAnchorElement, LinkWrapperProps>(
  ({ href, active, children, ...props }, ref) => {
    return (
      <Link href={href}>
        <a
          ref={ref}
          className={active ? classes.linkActive : classes.linkInactive}
          {...props}
        >
          {children}
        </a>
      </Link>
    );
  }
);

LinkWrapper.displayName = 'LinkWrapper';
{links.map((link) => {
  return (
    <Menu.Item key={link.href}>
      {({ a…

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by njncalub
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Help
Labels
None yet
1 participant