infoalloggi-monorepo/apps/infoalloggi/src/providers/AnnuncioProvider.tsx

15 lines
419 B
TypeScript

import { createContext, useContext } from "react";
import type { Annunci } from "~/schemas/public/Annunci";
export const AnnuncioContext = createContext<Pick<
Annunci,
"id" | "tipo" | "prezzo" | "codice"
> | null>(null);
export const useAnnuncio = () => {
const context = useContext(AnnuncioContext);
if (!context) {
throw new Error("useAnnuncio must be used within a AnnuncioProvider");
}
return context;
};