img chantier

This commit is contained in:
trochas
2025-12-09 11:15:06 +01:00
parent c581f1511f
commit 5b702122e2
9 changed files with 102 additions and 60 deletions

36
app/ContextChantier.tsx Normal file
View File

@@ -0,0 +1,36 @@
import { Chantier, Chef, exempleChantier } from '@/class/class';
import { createContext, ReactNode, useContext, useMemo, useState } from 'react';
type ChantierContextType = {
chantier: Chantier | null;
setChantier: (p: Chantier | null) => void;
};
const ChantierContext = createContext<ChantierContextType | null>(null);
type ChantierProviderProps = {
children: ReactNode;
};
export const ChantierProvider = ({ children }: ChantierProviderProps) => {
const [chantier, setChantier] = useState<Chantier | null>(null);
const value = useMemo(
() => ({ chantier, setChantier }),
[chantier]
);
return (
<ChantierContext.Provider value={value}>
{children}
</ChantierContext.Provider>
);
};
export const useChantier = () => {
const context = useContext(ChantierContext);
if (!context) {
throw new Error('useChantier doit être utilisé dans <ChantierProvider>');
}
return context;
};