arqex / react-datetime

A lightweight but complete datetime picker react component.
2k stars 872 forks source link

The time picker hit some race condition and is buggy when using a controlled value #827

Open paintoshi opened 2 years ago

paintoshi commented 2 years ago

I'm Submitting a ...

[ x ] Bug report
[ ] Feature request
[ ] Support request

Steps to Reproduce

I'm using the datepicker value in order to update it programmatically. From what I can find on the docs, this should be the correct way of doing it.

const [curentDate, setCurentDate] = React.useState(initValue)
const onChangeDate = (date: any) => {
    setCurentDate(date)
}
<Datetime
    value={curentDate}
    onChange={onChangeDate}
    ....

Expected Results

Selecting a date and time should be smooth.

Actual Results

Selecting the date is fine, but when increasing/desceasing hours/min it works about 50% of the time. It instantly switches back to the previous value. Removing "value" from the datePicker and using the initalValue instead solves the problem, but then I can't change the date from other components.

https://user-images.githubusercontent.com/88572775/162618285-fb4c8f83-dfe4-4fc2-8401-ba0413167908.mp4