Created basic calendar context
This commit is contained in:
parent
9d9e2b7b39
commit
fd28aaee6c
38
src/context.tsx
Normal file
38
src/context.tsx
Normal file
@ -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<SetStateAction<CalendarContextStateT>>
|
||||||
|
}
|
||||||
|
|
||||||
|
const initialCalendarContextState: CalendarContextStateT = {
|
||||||
|
month: 1,
|
||||||
|
year: 1,
|
||||||
|
firstDayOfMonth: 0,
|
||||||
|
lastDayOfMonth: 0,
|
||||||
|
numberOfDays: 0,
|
||||||
|
}
|
||||||
|
|
||||||
|
export const CalendarContext = createContext<CalendarContextT>({
|
||||||
|
state: initialCalendarContextState,
|
||||||
|
})
|
||||||
|
|
||||||
|
export const CalendarProvider: React.FC = ({ children }) => {
|
||||||
|
const [state, setState] = useState<CalendarContextStateT>(
|
||||||
|
initialCalendarContextState
|
||||||
|
)
|
||||||
|
|
||||||
|
return (
|
||||||
|
<CalendarContext.Provider value={{ state, setState }}>
|
||||||
|
{children}
|
||||||
|
</CalendarContext.Provider>
|
||||||
|
)
|
||||||
|
}
|
@ -1,7 +1,12 @@
|
|||||||
import * as React from "react";
|
import React from 'react'
|
||||||
|
import { CalendarProvider as CalendarContextProvider } from './context'
|
||||||
|
|
||||||
const Calendar: React.FC = () => {
|
const Calendar: React.FC = () => {
|
||||||
return <div>Calendar</div>;
|
return (
|
||||||
};
|
<CalendarContextProvider>
|
||||||
|
<div></div>
|
||||||
|
</CalendarContextProvider>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
export default Calendar;
|
export default Calendar
|
||||||
|
Loading…
x
Reference in New Issue
Block a user