mirror of
https://github.com/qier222/YesPlayMusic.git
synced 2025-02-28 04:21:53 +08:00
21 lines
566 B
TypeScript
21 lines
566 B
TypeScript
import { useLayoutEffect } from 'react'
|
|
import scrollPositions from '@/web/states/scrollPositions'
|
|
import { throttle } from 'lodash-es'
|
|
|
|
const ScrollRestoration = () => {
|
|
useLayoutEffect(() => {
|
|
const main = document.querySelector('main')
|
|
const handleScroll = throttle(() => {
|
|
scrollPositions.set(window.location.pathname, main?.scrollTop ?? 0)
|
|
}, 100)
|
|
main?.addEventListener('scroll', handleScroll)
|
|
return () => {
|
|
main?.removeEventListener('scroll', handleScroll)
|
|
}
|
|
}, [])
|
|
|
|
return <></>
|
|
}
|
|
|
|
export default ScrollRestoration
|