Configuration options for the scroll behavior
The scroll behavior: 'smooth', 'instant', or 'auto'. Defaults to 'smooth'
Optional callback function that fires when scrolling to top completes
Object containing scrollToTop function and isScrolling state
// Basic usage
const { scrollToTop } = useScrollToTop();
// With callback
const { scrollToTop, isScrolling } = useScrollToTop({
onScrollComplete: () => {
console.log('Reached the top!');
}
});
// With instant scroll
const { scrollToTop } = useScrollToTop({
behavior: 'instant',
onScrollComplete: () => {
// Fires immediately for instant scrolling
}
});
Hook that provides smooth scroll-to-top functionality with optional callback support.
Scrolls the window to the top of the page and optionally executes a callback function when the scroll operation completes. Uses a scroll event listener to detect when the scroll position reaches the top (scrollY === 0).