I am converting my HTML site to react and beneath the body tag, I have this script that toggles my mobile nav
<script>
window.addEventListener("scroll", function () {
var nav = document.querySelector("nav");
nav.classList.toggle("sticky", window.scrollY > 0);
}, { capture: true });
$(document).ready(function () {
$('.fa-bars').click(function () {
$('nav ul').toggleClass('active-2');
})
});
</script>
Then once I go to another page, the nav button stops working(i.e it won't toggle the nav until I refresh the page)
Please how can I fix that?