From fd28aaee6c1d9ccde0f53832b551425cac0fc39e Mon Sep 17 00:00:00 2001 From: Dm1tr1y147 Date: Tue, 27 Oct 2020 22:58:08 +0500 Subject: [PATCH] Created basic calendar context --- src/context.tsx | 38 ++++++++++++++++++++++++++++++++++++++ src/index.tsx | 13 +++++++++---- 2 files changed, 47 insertions(+), 4 deletions(-) create mode 100644 src/context.tsx diff --git a/src/context.tsx b/src/context.tsx new file mode 100644 index 0000000..0d7fd14 --- /dev/null +++ b/src/context.tsx @@ -0,0 +1,38 @@ +import React, { createContext, Dispatch, SetStateAction, useState } from 'react' + +type CalendarContextStateT = { + month: number + year: number + firstDayOfMonth: number + lastDayOfMonth: number + numberOfDays: number +} + +type CalendarContextT = { + state: CalendarContextStateT + setState?: Dispatch> +} + +const initialCalendarContextState: CalendarContextStateT = { + month: 1, + year: 1, + firstDayOfMonth: 0, + lastDayOfMonth: 0, + numberOfDays: 0, +} + +export const CalendarContext = createContext({ + state: initialCalendarContextState, +}) + +export const CalendarProvider: React.FC = ({ children }) => { + const [state, setState] = useState( + initialCalendarContextState + ) + + return ( + + {children} + + ) +} diff --git a/src/index.tsx b/src/index.tsx index 8cd9fb8..ec3932e 100644 --- a/src/index.tsx +++ b/src/index.tsx @@ -1,7 +1,12 @@ -import * as React from "react"; +import React from 'react' +import { CalendarProvider as CalendarContextProvider } from './context' const Calendar: React.FC = () => { - return
Calendar
; -}; + return ( + +
+
+ ) +} -export default Calendar; +export default Calendar