computer-scienceangular-roadmapbackend-roadmapblockchain-roadmapdba-roadmapdeveloper-roadmapdevops-roadmapfrontend-roadmapgo-roadmaphactoberfestjava-roadmapjavascript-roadmapnodejs-roadmappython-roadmapqa-roadmapreact-roadmaproadmapstudy-planvue-roadmapweb3-roadmap
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
22 lines
493 B
22 lines
493 B
import { useEffect, useState } from 'react'; |
|
|
|
export function useScrollPosition() { |
|
const [scrollPosition, setScrollPosition] = useState<{ |
|
x: number; |
|
y: number; |
|
}>({ |
|
x: 0, |
|
y: 0, |
|
}); |
|
|
|
useEffect(() => { |
|
const handleScroll = () => { |
|
setScrollPosition({ x: window.scrollX, y: window.scrollY }); |
|
}; |
|
|
|
window.addEventListener('scroll', handleScroll); |
|
return () => window.removeEventListener('scroll', handleScroll); |
|
}, []); |
|
|
|
return scrollPosition; |
|
}
|
|
|