Skip to content
Advertisement

Tag: addeventlistener

React Using addEventListener(“scroll”, function()) and useState shows no transition

I want to change background color of navigation gradually with transition like this Article.js Article.css When I run these, class name ‘active’ is added to the [div] but its background color is changed quickly from rgb(248, 249, 250) to rgb(255, 255, 255). I think this is because addEventListener changes isScrolling every scroll and rerenders the [div] element and its children.

Not sure how to use addEventListener to watch for media query

I am trying to run a function when the window is resized and hits a certain size. The following was working perfectly: However, I got a warning that addListener is deprecated, so I’m attempting to change it without much success. I have tried the below, but doesn’t work. What should I be doing? I have also tried window.addEventListener(‘resize’, mobileSlider(mediaQuery)) without

Advertisement