Attempting to force update the date in a useEffect.
This commit is contained in:
@@ -7,7 +7,7 @@ import CalenderNav from "./CalenderNav";
|
|||||||
import Day from "./Day";
|
import Day from "./Day";
|
||||||
|
|
||||||
const Calender = (newDate?: UpdateCalendarProps): JSX.Element => {
|
const Calender = (newDate?: UpdateCalendarProps): JSX.Element => {
|
||||||
const { selectedDate, layout, updateDate, currDate } = useContext(CalenderContext);
|
const { selectedDate, layout, updateDate, currDate, setCurrDate } = useContext(CalenderContext);
|
||||||
const { stickersMonth } = useContext(StickersContext);
|
const { stickersMonth } = useContext(StickersContext);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
@@ -22,6 +22,14 @@ const Calender = (newDate?: UpdateCalendarProps): JSX.Element => {
|
|||||||
}
|
}
|
||||||
}, [newDate, updateDate]);
|
}, [newDate, updateDate]);
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
console.info("Check to update date.");
|
||||||
|
if (!isSameDay(currDate, new Date())) {
|
||||||
|
console.info("Updated date.")
|
||||||
|
setCurrDate(new Date());
|
||||||
|
}
|
||||||
|
}, [currDate, setCurrDate]);
|
||||||
|
|
||||||
// Simulated user settings context
|
// Simulated user settings context
|
||||||
const userSettings = {
|
const userSettings = {
|
||||||
theme: "default",
|
theme: "default",
|
||||||
|
|||||||
@@ -241,10 +241,11 @@ const CalenderContextProvider = ({
|
|||||||
};
|
};
|
||||||
|
|
||||||
// * Attempting to fix an issue with static generation where the date does not appear to be updating after initial generation.
|
// * Attempting to fix an issue with static generation where the date does not appear to be updating after initial generation.
|
||||||
const [currDate] = useState<Date>(new Date);
|
const [currDate, setCurrDate] = useState<Date>(new Date);
|
||||||
|
|
||||||
const calenderContextValues: CalenderContextState = {
|
const calenderContextValues: CalenderContextState = {
|
||||||
currDate,
|
currDate,
|
||||||
|
setCurrDate,
|
||||||
selectedDate,
|
selectedDate,
|
||||||
title: selectedDateInfo.title,
|
title: selectedDateInfo.title,
|
||||||
layout: selectedDateInfo.layout,
|
layout: selectedDateInfo.layout,
|
||||||
|
|||||||
1
types/CalenderContext.d.ts
vendored
1
types/CalenderContext.d.ts
vendored
@@ -56,6 +56,7 @@ interface UpdateCalendarProps {
|
|||||||
|
|
||||||
interface CalenderContextState {
|
interface CalenderContextState {
|
||||||
currDate: Date;
|
currDate: Date;
|
||||||
|
setCurrDate: React.Dispatch<React.SetStateAction<Date>>;
|
||||||
selectedDate: Date;
|
selectedDate: Date;
|
||||||
title: string;
|
title: string;
|
||||||
layout: MonthLayout;
|
layout: MonthLayout;
|
||||||
|
|||||||
Reference in New Issue
Block a user