InvestWeb/pages/_app.tsx

46 lines
1.4 KiB
TypeScript
Raw Normal View History

2022-11-23 17:20:36 -05:00
import "../styles/globals.css";
2022-12-08 10:01:43 -05:00
import type { ReactElement, ReactNode } from "react";
import type { NextPage } from "next";
2022-11-23 17:20:36 -05:00
import type { AppProps } from "next/app";
import { AnimatePresence, domAnimation, LazyMotion } from "framer-motion";
2023-02-06 20:06:13 -05:00
import { Router } from "next/router";
2022-11-23 17:20:36 -05:00
2022-12-08 10:01:43 -05:00
export type NextPageWithLayout<P = {}, IP = P> = NextPage<P, IP> & {
getLayout?: (page: ReactElement) => ReactNode;
};
type AppPropsWithLayout = AppProps & {
Component: NextPageWithLayout;
};
2023-02-06 20:06:13 -05:00
const routeChange = () => {
// Temporary fix to avoid flash of unstyled content
// during route transitions. Keep an eye on this
// issue and remove this code when resolved:
// https://github.com/vercel/next.js/issues/17464
const tempFix = () => {
const allStyleElems = document.querySelectorAll('style[media="x"]');
allStyleElems.forEach((elem) => {
elem.removeAttribute("media");
});
};
tempFix();
};
Router.events.on("routeChangeComplete", routeChange);
Router.events.on("routeChangeStart", routeChange);
2022-12-08 10:01:43 -05:00
export default function App({ Component, pageProps }: AppPropsWithLayout) {
// Use the layout defined at the page level, if available
const getLayout = Component.getLayout ?? ((page) => page);
return (
<LazyMotion features={domAnimation}>
<AnimatePresence mode="wait" initial={false}>
{getLayout(<Component {...pageProps} />)}
</AnimatePresence>
</LazyMotion>
);
2022-11-23 17:20:36 -05:00
}