Files
HouseholdBudgetBook/frontend/src/context/contextState.ts
T

24 lines
583 B
TypeScript

import { createContext, type Dispatch } from 'react'
export interface AppState {
selectedYear: string
selectedMonth: string
}
export type AppAction =
| { type: 'SET_YEAR'; year: string }
| { type: 'SET_MONTH'; month: string }
export const initialState: AppState = (() => {
const now = new Date()
return {
selectedYear: now.getFullYear().toString(),
selectedMonth: (now.getMonth() + 1).toString().padStart(2, '0'),
}
})()
export const AppCtx = createContext<{
state: AppState
dispatch: Dispatch<AppAction>
}>({ state: initialState, dispatch: () => {} })