I made this spinner in a file preload.tsx:
"use client";
import { useState, useEffect } from "react";
import { TbLoader2 } from "react-icons/tb";
export default function Preloader() {
const [loading, setLoading] = useState(true);
useEffect(() => {
const Timer = setTimeout(() => {
setLoading(false);
}, 2000);
return () => clearTimeout(Timer);
}, []);
return loading ? (
<div className="h-screen flex items-center justify-center">
<TbLoader2 className="h-8 w-8 animate-spin" />
</div>
) : null;
}
Then in layout I just display it like this: <Preload />
How can I make it so when the loader is active, other content of the page is all hidden and after 2 seconds loader disappears and initial page's content is visible?
