我用Comp作为Link的子节点出现警告是什么原因

来源:3-2 页面跳转

cyper

2020-08-22

// pages/index.js

import Comp from '../components/comp'
import Link from 'next/link'
import {Button} from 'antd'

const Named = () => (
  <Link href="/a">
    <Comp>Index</Comp>
  </Link>
)
export default Named

// components/comp.jsx
const Comp = ({children}) => <button>{children}</button>
export default Comp;

点Link没反应。 控制台出现警告。

react-dom.development.js?61bb:88 Warning: Function components cannot be given refs. Attempts to access this ref will fail. Did you mean to use React.forwardRef()?

Check the render method of Link.
in Comp (at pages/index.js:8)
in Link (at pages/index.js:7)
in Named (created by App)
in App
in ErrorBoundary (created by ReactDevOverlay)
in ReactDevOverlay (created by Container)
in Container (created by AppContainer)
in AppContainer
in Root

写回答

1回答

Jokcy

2020-08-22

Function components cannot be given refs. 你的组件是函数组件吧?

0
0

全栈进阶课程 React16.8+Next.js+Koa2一步到位开发Github

学习React/Next.js服务端渲染SSR同构设计方案,理解OAuth登录体系的实现原理

651 学习 · 311 问题

查看课程