|
@@ -1,4 +1,4 @@
|
|
|
-import React, { ChangeEvent, useContext } from 'react';
|
|
|
+import React, { ChangeEvent, useContext, useEffect } from 'react';
|
|
|
import { AppContext } from '../../layout/AppContext';
|
|
|
import { getDateString } from '../../utils/date';
|
|
|
import styles from './caloriesDateInput.css';
|
|
@@ -6,10 +6,13 @@ import styles from './caloriesDateInput.css';
|
|
|
function CaloriesDateInput () {
|
|
|
const {selectedDate, setSelectedDate, setSelectedItem} = useContext(AppContext);
|
|
|
|
|
|
+ useEffect(() => {
|
|
|
+ setSelectedItem();
|
|
|
+ }, [selectedDate]);
|
|
|
+
|
|
|
function onDateChange (event: ChangeEvent<HTMLInputElement>) {
|
|
|
const newDate = (new Date(event.target.value)).getTime();
|
|
|
setSelectedDate(newDate);
|
|
|
- setSelectedItem();
|
|
|
}
|
|
|
|
|
|
const date = new Date(selectedDate);
|