简体   繁体   English

react-dates 无法在新的 DayPicker 读取 null 的属性“克隆”

[英]react-dates Cannot read property 'clone' of null at new DayPicker

I have below code我有以下代码

const [focusedInput, setFocusedInput] = useState('startDate');
const onFocusChange = fInput => {
  setFocusedInput(!fInput ? 'startDate' : fInput);
};

<DayPickerRangeController
  key={dateRange.startDate}
  startDate={dateRange.startDate}
  endDate={dateRange.endDate}
  onDatesChange={onDatesChange}
  onFocusChange={onFocusChange}
  focusedInput={focusedInput}
  numberOfMonths={2}
  isOutsideRange={day => moment().diff(day) < 0}
  initialVisibleMonth={() => dateRange.startDate}
/>

initialVisibleMonth causing the issue导致问题的initialVisibleMonth

Cannot read property 'clone' of null at new DayPicker无法在新的 DayPicker 读取 null 的属性“克隆”

I tried googling alot but didn't find any solution.我尝试了很多谷歌搜索,但没有找到任何解决方案。 What I am trying move the calendar to first month.. like I am on dec 2020 and someone select this year, it should show the the calendar to jan 2020, This year selection is fine, I am seeing the whole year is selected in calendar just the month is not shifting to jan so that it can be visible我正在尝试将日历移动到第一个月..就像我在 2020 年 12 月和今年有人 select 一样,它应该将日历显示到 2020 年 1 月,今年的选择很好,我看到在日历中选择了全年只是月份没有转移到 jan 以便它可以看到

Any idea任何想法

Thanks谢谢

You've passed a function not a value to initialVisibleMonth prop.您已将 function 传递给initialVisibleMonth道具,而不是值。 dateRange.startDate seems like not a function, but you used it like a function. dateRange.startDate似乎不是 function,但您使用它就像 function 一样。

Change改变

initialVisibleMonth={() => dateRange.startDate}

to

initialVisibleMonth={dateRange.startDate}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM