简体   繁体   English

警告:无法为 Function 组件提供参考。 尝试访问此 ref 将失败。 你是想使用 React.forwardRef() 吗?

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

I have this warning in my console, when I use nextJs Link component.当我使用nextJs Link组件时,我的控制台中出现了这个警告。 Can you help me solve this problem and explain me why.你能帮我解决这个问题并解释一下原因吗?

here is the console message这是控制台消息

在此处输入图像描述

here is my piece of code这是我的一段代码

import React from "react";
import Image from 'next/image'
import Link from 'next/link'

import logo from '/public/Images/E2R5_white.png';


const Logo = () => {

    return (
        <div className="">
            <Link href="/">
                <Image
                    src={logo}
                    height="50"
                    width={"80"}
                    alt="Logo - E2R5"
                />
            </Link>
        </div>)
}

export default Logo;

Thank you for your help.谢谢您的帮助。

The quick solution is to use <a> tag inside Link .快速的解决方案是在Link中使用<a>标签。

 <Link href="/">
   <a>
      <Image src={logo} height="50" width={ "80"} alt="Logo - E2R5" />
   </a>
 </Link>

Useful link to read: https://nextjs.org/docs/api-reference/next/link#if-the-child-is-a-functional-component有用的阅读链接: https://nextjs.org/docs/api-reference/next/link#if-the-child-is-a-functional-component

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 无法为 Function 组件提供参考。 尝试访问此 ref 将失败。 你是想使用 React.forwardRef() 吗? - Function components cannot be given refs. Attempts to access this ref will fail. Did you mean to use React.forwardRef()? 如何摆脱错误功能组件不能被赋予参考。 尝试访问此 ref 将失败。 你的意思是使用 React.forwardRef() 吗? - How to get rid off error Function components cannot be given refs. Attempts to access this ref will fail. Did you mean to use React.forwardRef()? 尝试访问此 ref 将失败。 你的意思是使用 React.forwardRef() - Attempts to access this ref will fail. Did you mean to use React.forwardRef() 函数组件不能有引用。 你的意思是使用 React.forwardRef() 吗? - Function components cannot have refs. Did you mean to use React.forwardRef()? ReactJS:React-Month-Picker 错误:函数组件不能有引用。 你的意思是使用 React.forwardRef() 吗? - ReactJS: React-Month-Picker Error: Function components cannot have refs. Did you mean to use React.forwardRef()? 错误:Function 组件不能有参考。? - Error : Function components cannot have refs.? 警告:函数组件不能被赋予 refs - Warning: Function components cannot be given refs 理解:警告:Function 组件不能给出参考 - Understanding: Warning: Function components cannot be given refs 来自 React.forwardRef 的 ref 为空 - ref from React.forwardRef is null 如何使用 React.forwardRef? - How to use React.forwardRef?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM