0

I want to show a loading icon while fetching data from external API using getseversideprops.The loading indicator is working while changing the route but i want to show loading indicator while pre-rendering the page using getServerSideProps.

Paras Buda
  • 51
  • 1
  • 6
  • Fetching data with `getServerSideProps` will block rendering until the HTML is generated on the server (server-side rendered) on the first request. – juliomalves Aug 05 '21 at 05:35

1 Answers1

0

I use this code

useEffect(() => {
    const handleStart = () => { setPageLoading(true); };
    let handleComplete = () => {
        setTimeout(() => {
            setPageLoading(false);
        }, 500);
    };
    router.events.on('routeChangeStart', handleStart);
    router.events.on('routeChangeComplete', handleComplete);
    router.events.on('routeChangeError', handleComplete);
}, [router]);

setPageLoading for show loading

const [pageLoading, setPageLoading] = useState<boolean>(false);