navigation-progress.tsx 582 B

12345678910111213141516171819202122232425
  1. import { useEffect, useRef } from 'react'
  2. import { useRouterState } from '@tanstack/react-router'
  3. import LoadingBar, { type LoadingBarRef } from 'react-top-loading-bar'
  4. export function NavigationProgress() {
  5. const ref = useRef<LoadingBarRef>(null)
  6. const state = useRouterState()
  7. useEffect(() => {
  8. if (state.status === 'pending') {
  9. ref.current?.continuousStart()
  10. } else {
  11. ref.current?.complete()
  12. }
  13. }, [state.status])
  14. return (
  15. <LoadingBar
  16. color='var(--muted-foreground)'
  17. ref={ref}
  18. shadow={true}
  19. height={2}
  20. />
  21. )
  22. }