Skip to content

Commit

Permalink
forgot to update start date and end date in parent component for the …
Browse files Browse the repository at this point in the history
…first time
  • Loading branch information
sam9116 committed Feb 6, 2024
1 parent c744e5c commit 49d13f1
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions src/PickDate.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,17 @@ import { useEffect, useState } from "react"
import "react-datepicker/dist/react-datepicker.css";

function PickDate({ updateStartDateInParent, updateEndDateInParent }) {
let cachedStartDate = localStorage.getItem('startDate');
let cachedEndDate = localStorage.getItem('endDate');

const today = new Date();
const oneYearFromNow = new Date(today);
oneYearFromNow.setFullYear(today.getFullYear() + 1);

const [startDate, setStartDate] = useState(new Date());
const [endDate, setEndDate] = useState(new Date());
useEffect(()=>{setStartDate(today); setEndDate(oneYearFromNow);},[])
const [startDate, setStartDate] = useState(cachedStartDate === null ? new Date() : new Date(cachedStartDate));
const [endDate, setEndDate] = useState(cachedEndDate === null ? oneYearFromNow : new Date(cachedEndDate));

useEffect(() => { updateStartDateInParent(startDate); updateEndDateInParent(endDate) }, [])
// Display spotify token
return (
<div>
Expand Down

0 comments on commit 49d13f1

Please sign in to comment.