NextLink is 1 step behind

13 views Asked by At

So this is my component state:

export default function DateNavigator() { 
  const [currentDate, setCurrentDate] = useState(new Date());
  const urlDate = formatToDateOnlyISO(currentDate);
  console.log(urlDate) // 2023-11-25
  
  return (
    <Link href={`?date=${urlDate}`} onClick={goToPrevDate}>
          ...
    </Link>
  )

}

and url is http://localhost:3000/top-trends

now when user goes back or previous, day is incremented with one but url is 1 step behind, so if today is:

2023-11-25 and user press back, date is correctly updated to 2023-11-24, however then query param in the url is displayed as 2023-11-25 so is always 1 step behind, any idea how to synchronize it

0

There are 0 answers