mantinedev / next-pages-template

Mantine + Next.js pages router template
https://mantine.dev/guides/next/
MIT License
485 stars 131 forks source link

NextLink children prop #2

Closed iodimitrov closed 3 years ago

iodimitrov commented 3 years ago

Hi,

When there are children present in the <NextLink /> component, the linter gives an error that children for the component are not supported.

I solved it by adding React.PropsWithChildren:

import React, { forwardRef } from 'react';
import Link from 'next/link';

export const NextLink = forwardRef(
  (
    { href, ...others }: React.PropsWithChildren<React.ComponentPropsWithoutRef<typeof Link>>,
    ref: React.ForwardedRef<HTMLAnchorElement>
  ) => (
    <Link href={href}>
      {/* eslint-disable-next-line jsx-a11y/anchor-has-content */}
      <a {...others} ref={ref} />
    </Link>
  )
);
rtivital commented 3 years ago

NextLink is a legacy component, that was used for elementRef prop. Since version 3.0 you should be able to use next Link component without wrappers:

<Link href="/hello">
  <Anchor>Your link</Anchor>
</Link>
iodimitrov commented 3 years ago

Thank you :))