xylabs/sdk-react

View on GitHub
packages/scroll-to-top/src/ScrollToTop.tsx

Summary

Maintainability
A
0 mins
Test Coverage
import { useEffect } from 'react'
import { useLocation } from 'react-router-dom'

// The point of this component it to return to the top of the page on any router navigate

export const ScrollToTop = () => {
  const { pathname } = useLocation()
  useEffect(() => {
    window.scrollTo(0, 0)
  }, [pathname])

  return null
}