尝试实施react-calendar,后退和下一步按钮(更改日期)引发了此错误:
未捕获的TypeError:无法读取未定义的属性“0”
它之前正在工作,我的代码中没有任何改变,所以我很困惑。
为什么我无法在react-big-calendar上使用next和back按钮(更改日期)?
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
})
);
});
};
答案 0 :(得分:1)
应用defaultDate属性解决了这个问题。
<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