19 lines
645 B
TypeScript
19 lines
645 B
TypeScript
'use client';
|
|
import { combineDateTime } from '@/utils/date';
|
|
import { createContext, useMemo, useState } from 'react';
|
|
|
|
type ContextType = {
|
|
selectedDate: Date;
|
|
setSelectedDate: (date: Date) => void;
|
|
};
|
|
|
|
export const ScheduleSlotsContext = createContext<ContextType>({} as ContextType);
|
|
|
|
export function ScheduleSlotsProvider({ children }: { readonly children: React.ReactNode }) {
|
|
const [selectedDate, setSelectedDate] = useState(combineDateTime(new Date(), '00:00'));
|
|
|
|
const value = useMemo(() => ({ selectedDate, setSelectedDate }), [selectedDate]);
|
|
|
|
return <ScheduleSlotsContext value={value}>{children}</ScheduleSlotsContext>;
|
|
}
|