added Context
This commit is contained in:
18
app/AppContext.tsx
Normal file
18
app/AppContext.tsx
Normal 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;
|
||||
}
|
||||
Reference in New Issue
Block a user