AppContext.ts 635 B

123456789101112131415161718192021222324
  1. import { createContext } from "react";
  2. import { getDateString } from '../utils/date';
  3. type AppContextType = {
  4. selectedDate: number,
  5. setSelectedDate: (selectedDate: number) => void,
  6. calorieItems: CalorieItems;
  7. setCalorieItems: (calorieItems: CalorieValue[]) => void,
  8. selectedItem: CalorieValue | undefined,
  9. setSelectedItem: (item?: CalorieValue) => void
  10. };
  11. const AppContext = createContext<AppContextType>({
  12. calorieItems: [],
  13. selectedDate: Date.now(),
  14. selectedItem: undefined,
  15. setCalorieItems: () => [],
  16. setSelectedDate: () => getDateString(new Date()),
  17. setSelectedItem: () => {}
  18. });
  19. export {
  20. AppContext
  21. };