mirror of
https://github.com/AykutSarac/jsoncrack.com.git
synced 2025-01-27 15:22:56 +08:00
add loading on routing
This commit is contained in:
parent
d1f5e909f7
commit
5e2b810db5
@ -1,9 +1,29 @@
|
||||
import React from "react";
|
||||
import GlobalStyle from "src/constants/globalStyle";
|
||||
import { darkTheme } from "src/constants/theme";
|
||||
import type { AppProps } from "next/app";
|
||||
import { ThemeProvider } from "styled-components";
|
||||
import { useRouter } from "next/router";
|
||||
import { Loading } from "src/components/Loading";
|
||||
|
||||
function AykutSarac({ Component, pageProps }: AppProps) {
|
||||
const router = useRouter();
|
||||
const [pageLoading, setPageLoading] = React.useState<boolean>(false);
|
||||
React.useEffect(() => {
|
||||
const handleStart = () => {
|
||||
setPageLoading(true);
|
||||
};
|
||||
const handleComplete = () => {
|
||||
setPageLoading(false);
|
||||
};
|
||||
|
||||
router.events.on("routeChangeStart", handleStart);
|
||||
router.events.on("routeChangeComplete", handleComplete);
|
||||
router.events.on("routeChangeError", handleComplete);
|
||||
}, [router]);
|
||||
|
||||
if (pageLoading) return <Loading />;
|
||||
|
||||
return (
|
||||
<ThemeProvider theme={darkTheme}>
|
||||
<GlobalStyle />
|
||||
|
Loading…
x
Reference in New Issue
Block a user