Hacker0x01 / react-datepicker

A simple and reusable datepicker component for React

Home Page:https://reactdatepicker.com/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Error using time select

UnknownVladyslav opened this issue · comments

Hi! I'm using react-datepicker on two projects. Both projects have same 4.8.0 version of library, but in the first i faced with a problem. I need to use showTimeSelect prop and when i select date (or select time firstly and then click on filled field), app crashes with an error as on screenshot. I use react-datepicker with react-hook-form's useController, i try to use almost identical datepicker components, but in one project i still have an error. I convert received value to timestamp and provide it to controller in the both components. Please, write if you need to be provided with more data or description, i`ll send it!

image

commented

Hello
Most likely your date is undefined or null here

const startOfDay = new Date(d.getFullYear(), d.getMonth(), d.getDate());

Thank a lot for reply!
I looked that this function gets selected prop to work with. I understand that it can drop an error because of providing timestamp value to component. But i tried to provide hardcoded timestamp value to similar components on screenshots with the similar other props and here we have two different results. First picture made in project where component drops an error just by clicking the input with hardcoded value, in the second case we can normally operate with the datepicker without errors (of course we have hardcoded value too, but we have controller value changing). So it looks weird for me now why we have different result using the same value for selected prop. On the third picture is the example of calendar working in the second project. But if i just clicking on prefilled input on the last screenshot - it crashes :(

image
image
image
image

commented

try to isolate the selected prop from the rest of the optional props because one of them may affect business logic.
also, try to reproduce the problem on the latest version of the library -- 6.9.0

I'm sorry, i forgot to write that update to 6.9.0 version didn't solve the problem. I played with props, only prop showTimeSelect affects on error. I used calendar in the second project without time selection, but i added it to check how would it work and it works ok. In the first project i have no error without showTImeSelect property.

commented

I have more concerns about {...rest} spread

the library will be converted to TS soon #4700 so it might help with debugging your problem

Rest is just empty object, i tried to remove influence of unnecessary props on component.
image