Files
portfolio/app/layout.tsx

46 lines
1.2 KiB
TypeScript

// app/layout.tsx
"use client";
import {SpeedInsights} from "@vercel/speed-insights/next";
import {Analytics} from "@vercel/analytics/next";
import "./globals.css";
import {Roboto} from 'next/font/google';
import React, {useEffect, useState} from "react";
import ClientCookieConsentBanner from "./components/ClientCookieConsentBanner";
const roboto = Roboto({
variable: '--font-roboto',
weight: '400',
subsets: ['latin'],
});
export default function RootLayout({
children,
}: {
children: React.ReactNode;
}) {
const [consent, setConsent] = useState<string | null>(null);
useEffect(() => {
const storedConsent = localStorage.getItem("CookieConsent");
setConsent(storedConsent);
}, []);
const handleConsentChange = (newConsent: string) => {
setConsent(newConsent);
};
return (
<html lang="en">
<body className={roboto.variable}>
<ClientCookieConsentBanner onConsentChange={handleConsentChange}/>
{children}
{consent === "accepted" && <SpeedInsights/>}
{consent === "accepted" && <Analytics/>}
</body>
</html>
);
}