question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

"onMouseEnter" was passed to <Link> with `href` of `/` but "legacyBehavior" was set

See original GitHub issue

Description

Passing a NextJs Link to Charka Link results in legacyBehaviour set

Link to Reproduction

None

Steps to reproduce

  1. Write Code
<NextLink href={navItem.href ?? "#"} passHref>
  <Link
    p={2}
    fontSize={"sm"}
    fontWeight={500}
    color={linkColor}
    _hover={{
      textDecoration: "none",
      color: linkHoverColor,
    }}
  >
    {navItem.label}
  </Link>
</NextLink>;

Chakra UI Version

2.0.0

Browser

Chrome/100.0.4896.127

Operating System

  • macOS
  • Windows
  • Linux

Additional Information

Passing legacyBehavior prop does not solve this issue

Issue Analytics

  • State:closed
  • Created a year ago
  • Comments:7 (1 by maintainers)

github_iconTop GitHub Comments

9reactions
henrycheacommented, Jun 1, 2022

I’ve managed to resolve the issue. It due to the props not being passed. I created a custom component like below

import Link, { LinkProps } from "next/link";
import {
  Link as ChakraLink,
  LinkProps as ChakraLinkProps,
} from "@chakra-ui/react";
import React from "react";

type ChakraLinkAndNextProps = ChakraLinkProps & LinkProps;

const ChakraNextLink = React.forwardRef(({ href, children, ...props } : ChakraLinkAndNextProps, ref : any) => {
  return (
    <Link href={href} passHref>
      <ChakraLink ref={ref} {...props}>
        {children}
      </ChakraLink>
    </Link>
  );
});

export default ChakraNextLink;
0reactions
anubra266commented, May 31, 2022

@henrychea could you give more info on the exact issue you have now. Feel free to reopen with a minimal reproduction.

Read more comments on GitHub >

github_iconTop Results From Across the Web

ERROR "onMouseEnter" was passed to <Link> with `href`
I got an error. "onMouseEnter" was passed to with `href` of `/FAQ` but "legacyBehavior" was set. The legacy behavior requires onMouseEnter ...
Read more >
How to overcome warning of "onClick" was passed to <Link ...
"onClick" was passed to with href of /discovery/edit but "legacyBehavior" was set. The legacy behavior requires onClick be set on the child ......
Read more >
next - NPM Package Compare versions - Socket.dev
console.warn(`"onMouseEnter" was passed to <Link> with \`href\` of \`${hrefProp}\` but "legacyBehavior" was set. The legacy behavior requires onMouseEnter ...
Read more >
onmouseenter Event - W3Schools
The onmouseenter event occurs when the mouse pointer enters an element. The onmouseenter event is often used together with the onmouseleave event, ...
Read more >
一文搞懂最强首屏渲染方案【Next.js】
`"onMouseEnter" was passed to <Link> with \`href\` of \`${hrefProp}\` but "legacyBehavior" was set. The legacy behavior requires ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found