mirror of
https://github.com/streamich/react-use.git
synced 2026-01-18 14:06:52 +00:00
fix: 🐛 cancel animation frame on un-mount in useWindowScroll()
This commit is contained in:
parent
94bffc514d
commit
bc021ce550
@ -16,7 +16,6 @@ const useWindowScroll = (): State => {
|
||||
useEffect(() => {
|
||||
const handler = () => {
|
||||
cancelAnimationFrame(frame.current)
|
||||
|
||||
frame.current = requestAnimationFrame(() => {
|
||||
setState({
|
||||
x: window.scrollX,
|
||||
@ -30,7 +29,10 @@ const useWindowScroll = (): State => {
|
||||
passive: true
|
||||
})
|
||||
|
||||
return () => window.removeEventListener('scroll', handler)
|
||||
return () => {
|
||||
cancelAnimationFrame(frame.current);
|
||||
window.removeEventListener('scroll', handler);
|
||||
};
|
||||
}, [])
|
||||
|
||||
return state
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user