react-big-calendar:无法读取未定义的 属性 '0'

react-big-calendar: Cannot read property '0' of undefined

问题

尝试执行 react-calendar 后退和下一步按钮(更改日期)抛出此错误:

Uncaught TypeError: Cannot read property '0' of undefined

它以前是有效的,我没有更改我的代码中的任何内容,所以我很困惑。

问题

为什么我无法在 react-big-calendar 上使用下一步和后退按钮(更改日期)?

代码:

import React, {Component} from 'react';
import BigCalendar from 'react-big-calendar';
import moment from 'moment';

// Setup the localizer by providing the moment (or globalize) Object
// to the correct localizer.
BigCalendar.momentLocalizer(moment); // or globalizeLocalizer

export default class CalendarComponent extends Component {

    constructor(props){
        super(props);

        this.state = {
            events: []
        }

    }

    render(){
        return (
            <div style={{flex: 1}}>
                <BigCalendar
                    events={this.state.events}
                    startAccessor='startDate'
                    endAccessor='endDate'
                />
            </div>
        );
    }
}

库错误行:

库中的这一行似乎失败了:

MonthView.prototype.renderHeaders = function renderHeaders(row, format, culture) {
    //failes here.
    var first = row[0];
    var last = row[row.length - 1];
    var HeaderComponent = this.props.components.header || _Header2.default;

    return _dates2.default.range(first, last, 'day').map(function (day, idx) {
      return _react2.default.createElement(
        'div',
        { key: 'header_' + idx, className: 'rbc-header' },
        _react2.default.createElement(HeaderComponent, {
          date: day,
          label: _localizer2.default.format(day, format, culture),
          localizer: _localizer2.default,
          format: format,
          culture: culture
        })
      );
    });
  };

应用默认日期 属性 解决了这个问题。

        <div style={{flex: 1}}>
            <BigCalendar
                events={this.state.events}
                startAccessor='startDate'
                endAccessor='endDate'
                defaultDate={moment().toDate()}
            />
        </div>

https://github.com/intljusticemission/react-big-calendar/issues/834