Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
218 views
in Technique[技术] by (71.8m points)

javascript - 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

Cannot read property 'clone' of null at new DayPicker

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

Any idea

Thanks


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

You've passed a function not a value to initialVisibleMonth prop. dateRange.startDate seems like not a function, but you used it like a function.

Change

initialVisibleMonth={() => dateRange.startDate}

to

initialVisibleMonth={dateRange.startDate}

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...