-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implement cursor pagination and infinity scroll in posts
- Loading branch information
1 parent
7266b5c
commit 090fde4
Showing
3 changed files
with
155 additions
and
49 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
import React, { useEffect, useState } from 'react'; | ||
import { ChevronUpIcon } from '@heroicons/react/24/outline'; | ||
|
||
const BackToTop = () => { | ||
const [showTopButton, setShowTopButton] = useState(false); | ||
|
||
useEffect(() => { | ||
const handleScroll = () => { | ||
if (window.scrollY > 900) { | ||
setShowTopButton(true); | ||
} else { | ||
setShowTopButton(false); | ||
} | ||
}; | ||
|
||
window.addEventListener('scroll', handleScroll); | ||
|
||
return () => { | ||
window.removeEventListener('scroll', handleScroll); | ||
}; | ||
}, []); | ||
|
||
const scrollToTop = () => { | ||
window.scrollTo({ top: 0, behavior: 'smooth' }); | ||
}; | ||
|
||
return ( | ||
showTopButton && ( | ||
<button | ||
onClick={scrollToTop} | ||
className="fixed bottom-8 right-8 bg-indigo-600 text-white p-2 rounded-full shadow-lg hover:bg-indigo-500 focus:outline-none dark:bg-gray-800 dark:text-gray-300 dark:hover:bg-gray-700" | ||
> | ||
<ChevronUpIcon className="h-6 w-6" /> | ||
</button> | ||
) | ||
); | ||
}; | ||
|
||
export default BackToTop; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters