selection chantier (animation,correction) ; ajustement et amélioration du thème ; chantier provider
This commit is contained in:
36
app/Context.tsx
Normal file
36
app/Context.tsx
Normal 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;
|
||||
};
|
||||
Reference in New Issue
Block a user