️ Lazy load animation library to help reduce bundle size (#502)

This commit is contained in:
Luke Vella 2023-02-10 09:24:01 +00:00 committed by GitHub
parent c2c000f770
commit 696cd44ba1
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
14 changed files with 115 additions and 83 deletions

View file

@ -1,23 +1,42 @@
import { AnimatePresence, domAnimation, LazyMotion, m } from "framer-motion";
import { useRouter } from "next/router";
import React from "react";
import { DayjsProvider } from "@/utils/dayjs";
import { NextPageWithLayout } from "../../types";
import ModalProvider from "../modal/modal-provider";
import { UserProvider } from "../user-provider";
import { MobileNavigation } from "./standard-layout/mobile-navigation";
const StandardLayout: React.VoidFunctionComponent<{
children?: React.ReactNode;
}> = ({ children, ...rest }) => {
const router = useRouter();
return (
<UserProvider>
<DayjsProvider>
<div className={"bg-pattern relative min-h-full"} {...rest}>
<MobileNavigation />
<div className="mx-auto max-w-4xl">{children}</div>
</div>
</DayjsProvider>
</UserProvider>
<LazyMotion features={domAnimation}>
<UserProvider>
<DayjsProvider>
<ModalProvider>
<div className={"bg-pattern relative min-h-full"} {...rest}>
<MobileNavigation />
<div className="mx-auto max-w-4xl">
<AnimatePresence initial={false} exitBeforeEnter={true}>
<m.div
key={router.asPath}
initial={{ opacity: 0, y: -50 }}
animate={{ opacity: 1, y: 0 }}
exit={{ opacity: 0, y: -50 }}
>
{children}
</m.div>
</AnimatePresence>
</div>
</div>
</ModalProvider>
</DayjsProvider>
</UserProvider>
</LazyMotion>
);
};