1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

【React/Next.js】自作コンポーネントをLinkで囲めない件

Posted at

結論

divで囲んでしまえば、とりあえず解決

環境

  • React 16.12.0
  • Next.js 10.0.4

事象

こうすると

import Link from "next/link";

<Link href={`/sample`}>
  <MyComponent/>
</Link>

怒られる。

Warning: Function components cannot be given refs.
Attempts to access this ref will fail. Did you mean to use React.forwardRef()?

再度 結論

React.forwardRefを使えというので、色々なサイトを元に試行錯誤しましたがうまくいきませんでした。

なので仕方なくこう

<Link href={`/sample`}>
  <div>
    <MyComponent/>
  </div>
</Link>
1
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?