简体   繁体   English

反应/错误:无法读取未定义的属性“addEventListener”

[英]React / Error: Cannot read property 'addEventListener' of undefined

I'm trying to find out where the error is coming from, I guess the useEffect() but as I am quite new with React, I'm taking a while to find it out and some help would be good.我试图找出错误来自哪里,我猜是 useEffect() 但由于我对 React 很陌生,所以我需要一段时间才能找到它,并且一些帮助会很好。 It is mapping an imported component (SliderTeaser).它正在映射一个导入的组件(SliderTeaser)。 在此处输入图像描述

带有 proptypes 和 styled-components 的 slider.js 文件

在此处输入图像描述

change改变

const carousel = React.useRef();

in your Slider component to在您的Slider组件中

const carousel = React.useRef(null);

as you can't attach the event listener to an undefined object, but a null object is not undefined.因为您不能将事件侦听器附加到未定义的 object,但 null object 不是未定义的。

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM