added Context

This commit is contained in:
Gavin McDonald
2025-06-25 17:04:18 -04:00
parent 59aa904c5a
commit e7ebb0223b
6 changed files with 75 additions and 16 deletions

18
app/AppContext.tsx Normal file
View File

@@ -0,0 +1,18 @@
'use client';
import { createContext, useContext, useState, ReactNode } from 'react';
import type { AppContext, Tilt } from '@/types';
const AppContext = createContext<AppContext | undefined>(undefined);
export function AppProvider({ children }: { children: ReactNode }) {
const [tilts, setTilts] = useState<Tilt[]>([]);
return <AppContext.Provider value={{ tilts, setTilts }}>{children}</AppContext.Provider>;
}
export function useAppContext(): AppContext {
const context = useContext(AppContext);
if (!context) throw new Error('useAppContext must be used within AppProvider');
return context;
}

View File

@@ -1,5 +1,6 @@
import type { Metadata } from 'next';
import { Pirata_One, Eagle_Lake, Cinzel_Decorative } from 'next/font/google';
import { AppProvider } from '@/app/AppContext';
import './globals.css';
const pirataOne = Pirata_One({
@@ -40,7 +41,9 @@ export default function RootLayout({
lang="en"
className={`${pirataOne.variable} ${eagleLake.variable} ${cinzel.variable} antialiased`}
>
<body className={`${eagleLake.className} antialiased`}>{children}</body>
<body className={`${eagleLake.className} antialiased`}>
<AppProvider>{children}</AppProvider>
</body>
</html>
);
}