Reputation: 1
I am trying to use React Scroll, but with this code in place whenever I scroll I get error:
TypeError: setScrollNav is not a function
export default function Navbar() {
const [showNav, setShowNav] = useState(false);
const setScrollNav = useState(false);
useEffect(() => {
function changeNav() {
if(window.scrollY >= 100) {
setScrollNav(true)
} else {
setScrollNav(false)
}
}
window.addEventListener('scroll', changeNav)
return () => window.removeEventListener('scroll', changeNav)
}, [setScrollNav])
return (
Upvotes: 0
Views: 289
Reputation: 7670
Here's the syntax of useState
const [count, setCount] = useState(0)
It returns an array, the second element of the array is the dispatch function.
Upvotes: 1