frondend/components/RouteLoader.tsx

25 lines
872 B
TypeScript

"use client"
import React, { useState, useEffect } from 'react'
import { usePathname, useSearchParams } from 'next/navigation'
import Loading from './Loading'
// const Loader = () => (
// <div className="fixed top-0 left-0 w-screen h-screen z-[99999999999999] flex items-center justify-center bg-black/40">
// <div className="animate-spin rounded-full h-32 w-32 border-t-2 border-b-2 border-white"></div>
// </div>
// );
export default function RouteLoader() {
const pathname = usePathname()
const searchParams = useSearchParams()
const [loading, setLoading] = useState<boolean>(false)
useEffect(() => {
setLoading(true)
const timer = setTimeout(() => setLoading(false), 300) // Adjust timeout as needed
return () => clearTimeout(timer)
}, [pathname, searchParams])
return loading ? <Loading /> : null
}