ERP-node/frontend/contexts/DashboardContext.tsx

35 lines
942 B
TypeScript
Raw Permalink Normal View History

"use client";
import React, { createContext, useContext, useState, ReactNode } from "react";
/**
* Context
* - /
*/
interface DashboardContextType {
selectedDate: Date | null;
setSelectedDate: (date: Date | null) => void;
}
const DashboardContext = createContext<DashboardContextType | undefined>(undefined);
export function DashboardProvider({ children }: { children: ReactNode }) {
const [selectedDate, setSelectedDate] = useState<Date | null>(null);
return (
<DashboardContext.Provider value={{ selectedDate, setSelectedDate }}>
{children}
</DashboardContext.Provider>
);
}
export function useDashboard() {
const context = useContext(DashboardContext);
if (context === undefined) {
throw new Error("useDashboard must be used within a DashboardProvider");
}
return context;
}