feat: implement auto scroll
This commit is contained in:
parent
a9993640ff
commit
b8d3ba85f5
6 changed files with 71 additions and 17 deletions
23
lib/hooks/use-at-bottom.tsx
Normal file
23
lib/hooks/use-at-bottom.tsx
Normal file
|
|
@ -0,0 +1,23 @@
|
|||
import * as React from 'react'
|
||||
|
||||
export function useAtBottom(offset = 0) {
|
||||
const [isAtBottom, setIsAtBottom] = React.useState(false)
|
||||
|
||||
React.useEffect(() => {
|
||||
const handleScroll = () => {
|
||||
setIsAtBottom(
|
||||
window.innerHeight + window.scrollY ===
|
||||
document.body.offsetHeight - offset
|
||||
)
|
||||
}
|
||||
|
||||
window.addEventListener('scroll', handleScroll, { passive: true })
|
||||
handleScroll()
|
||||
|
||||
return () => {
|
||||
window.removeEventListener('scroll', handleScroll)
|
||||
}
|
||||
}, [offset])
|
||||
|
||||
return isAtBottom
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue