I am trying to use scrollY to add and remove class using react. I have it working with jquery but can't seem to grasp how to convert it into React. Here is the before and after. I am lost on how to target .navbar that lives in Navbar.js in a different folder as well. Please help!
$(document).ready(function(){
$(window).scroll(function(){
// sticky navbar on scroll script
if(this.scrollY > 20){
$('.navbar').addClass("sticky");
}else{
$('.navbar').removeClass("sticky");
}
import React, { Component, useEffect } from 'react';
import Animate from 'animate.css-react';
import Navbar from '../Navigation/Navbar'
export default function Scroll() {
const[scroll, setScroll] = useState(false);
useEffect(() => {
window.addEventListener("scroll", () => {
if(window.scrollY > 20) {
$('.navbar').addClass("sticky");
}else{
$('.navbar').removeClass("sticky");
}
});
}, []);
}