gpbl / react-day-picker

DayPicker is a customizable date picker component for React. Add date pickers, calendars, and date inputs to your web applications.

Home Page:https://daypicker.dev

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Bug: defaultSelected doesn't update if the value changes after the first render

markcnunes opened this issue · comments

Bug description

defaultSelected from useInput doesn't update if the value changes after the first render.
This is an issue if the data is being fetched because it starts as undefined and finishes as a date but useInput doesn't update the defaultSelected.

To reproduce

https://codesandbox.io/s/error-useinput-from-react-day-picker-hlspx8

Steps

  1. Initiate useInput with defaultSelected as undefined
  2. Change defaultSelected to a Date

Expected behavior

It would make sense if useInput allowed defaultSelected to be modified.

Screenshots

If applicable, add screenshots to help explain your problem.

Additional context

The input field is undefined if the value changes after the first render
image

It works fine when the date is provided in the first render
image

I am currently having to overwrite the value for the input tag to be able to allow the input to display the right value after the first render.

  <Input
          {...inputProps}
          value={value ? new Date(value) : undefined}

I am facing the same issue and would love to see a resolution.