Commit 71f9288a authored by Olivier Tassinari's avatar Olivier Tassinari Committed by kodiakhq[bot]

Fix onError prop-type warning in Link (#8021)

The warning

> Warning: Failed prop type: Link: unknown props found: onError

can happen in this case:

```tsx
import * as React from 'react';
import NextLink, { LinkProps as NextLinkProps } from 'next/link';

type NextComposedProps = React.AnchorHTMLAttributes<HTMLAnchorElement> & NextLinkProps;

const NextComposed = React.forwardRef<HTMLAnchorElement, NextComposedProps>((props, ref) => {
  const { as, href, replace, scroll, passHref, shallow, prefetch, onError, ...other } = props;

  return (
    <NextLink
      href={href}
      prefetch={prefetch}
      as={as}
      replace={replace}
      scroll={scroll}
      shallow={shallow}
      passHref={passHref}
      onError={onError}
    >
      <a ref={ref} {...other} />
    </NextLink>
  );
});
```

*Taken from Material-UI Next.js integration example*
parent 22b58b1c
...@@ -52,7 +52,6 @@ export type LinkProps = { ...@@ -52,7 +52,6 @@ export type LinkProps = {
scroll?: boolean scroll?: boolean
shallow?: boolean shallow?: boolean
passHref?: boolean passHref?: boolean
onError?: (error: Error) => void
prefetch?: boolean prefetch?: boolean
} }
...@@ -180,9 +179,6 @@ class Link extends Component<LinkProps> { ...@@ -180,9 +179,6 @@ class Link extends Component<LinkProps> {
document.body.focus() document.body.focus()
} }
}) })
.catch((err: any) => {
if (this.props.onError) this.props.onError(err)
})
} }
prefetch() { prefetch() {
......
...@@ -5,7 +5,6 @@ export default () => { ...@@ -5,7 +5,6 @@ export default () => {
const props: LinkProps = { const props: LinkProps = {
href: '/page', href: '/page',
as: '/as-page', as: '/as-page',
onError() {},
} }
return ( return (
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment