react运用ref报错返回undefined或null是什么原因,下面web建站小编给大家介绍一下解决方法!
原因分析:导致报错的原因是在触发之前就执行了ref。
正确写法:
import {useRef, useEffect} from 'react';
export default function App() {
const ref = useRef();
console.log(ref.current); // ?️ undefined here
useEffect(() => {
const el2 = ref.current;
console.log(el2); // ?️ element here
}, []);
const handleClick = () => {
console.log(ref.current); // ?️ element here
};
return (
<div>
<div ref={ref}>
<h2>Hello</h2>
</div>
<button onClick={handleClick}>Click</button>
</div>
);
}
el-dialog中获取el-table组件的ref值报undefined错误!
vuejs点击重置报"TypeError: Cannot read properties of undefined (reading 'resetFields')"错误
上面是“react运用ref报错返回undefined或null怎么解决”的全面内容,想了解更多关于 reactjs 内容,请继续关注web建站教程。
当前网址:https://ipkd.cn/webs_3275.html
workflows工作流
在白雪覆盖的广阔平原上两只可爱的小猫
懂王特朗普3d漫画ComfyUI工作流
一个熙熙攘攘的市场场景,里面摆满了南瓜
瀑布边坐着一位披着斗篷的隐士
一只迷人的黑豹ComfyUI工作流
一种长着彩虹翅膀的虫子comfyui工作流
文生图工作流:一幅海底睡莲,碧海蓝天comfyui工
大黄蜂空中决战ComfyUI工作流
猜你喜欢
声明:本站提供的所有资源部分来自互联网,如果有侵犯您的版权或其他权益,请发送到邮箱:admin@ipkd.cn,我们会在看到邮件的第一时间内为您处理!

利用CSS3代码编写45款按钮效果
css3绘制一个会动的大嘴鸟
css3实现星球旋转
3d文字动画效果
js+css3做一个灯泡开灯关灯效果
barcode条形码/qrcode二维码兼容所有浏览器(含ie6/ie7/ie8)
纯html+css做一个3d统计效果
做一个好玩的时钟翻牌效果












