Reactjs 反应日期选择器句柄空日期和时间值

Reactjs 反应日期选择器句柄空日期和时间值,reactjs,datepicker,Reactjs,Datepicker,我在react中有一个带有时间组件的datepicker,它可以有空值或空值date <DatePicker selected={fromDttm} timeInputLabel="Time:" name="from_dttm" id="from_dttm" className="form-control" onChange={date => setFromDtttm(date)} dateFormat

我在react中有一个带有时间组件的datepicker,它可以有空值或空值date

 <DatePicker selected={fromDttm} timeInputLabel="Time:" name="from_dttm" id="from_dttm" className="form-control" onChange={date => setFromDtttm(date)} dateFormat="dd/MM/yyyy h:mm aa" showTimeInput />
这段代码在有有效的日期值时工作,但在没有日期值时出错。只有在使用time
showTimeInput
参数时才会发生这种情况。我没有问题,因为只有日期没有时间

下面是一个错误

   RangeError: Invalid time value
format
E:/fuel-man-workspace/fuelman-frontend/fuel-man-ui/node_modules/date-fns/esm/format/index.js:371
  368 | var originalDate = toDate(dirtyDate);
  369 | 
  370 | if (!isValid(originalDate)) {
> 371 |   throw new RangeError('Invalid time value');
      | ^  372 | } // Convert the date in system timezone to the same date in UTC+00:00 timezone.
  373 | // This ensures that when UTC functions will be implemented, locales will be compatible with them.
  374 | // See an issue about UTC functions: https://github.com/date-fns/date-fns/issues/376

我不知道为什么react datepicker不接受带有时间组件的日期字段的空值。有没有办法解决这个问题。如果
fromDTTM
变量没有值,我需要显示空输入。

我创建了一个示例,没有发现任何错误。区别是什么?我已经创建了一个示例,没有发现任何错误。有什么区别?
   RangeError: Invalid time value
format
E:/fuel-man-workspace/fuelman-frontend/fuel-man-ui/node_modules/date-fns/esm/format/index.js:371
  368 | var originalDate = toDate(dirtyDate);
  369 | 
  370 | if (!isValid(originalDate)) {
> 371 |   throw new RangeError('Invalid time value');
      | ^  372 | } // Convert the date in system timezone to the same date in UTC+00:00 timezone.
  373 | // This ensures that when UTC functions will be implemented, locales will be compatible with them.
  374 | // See an issue about UTC functions: https://github.com/date-fns/date-fns/issues/376