Skip to content

Instantly share code, notes, and snippets.

@enqtran
Created December 22, 2022 13:44
Show Gist options
  • Save enqtran/9f234d734731b499b5f5ba4150758cee to your computer and use it in GitHub Desktop.
Save enqtran/9f234d734731b499b5f5ba4150758cee to your computer and use it in GitHub Desktop.
import { useLayoutEffect } from 'react'
import { useLocation } from 'react-router-dom'
const ScrollToTop = () => {
const { pathname } = useLocation()
useLayoutEffect(() => {
window && window.scrollTo(0, 0)
}, [pathname])
return null
}
export default ScrollToTop
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment