在我的项目中,我试图初始化react-big-calendar,但这是说它不存在。
Uncaught TypeError: Cannot read property 'momentLocalizer' of undefined
我的软件包版本:“ react-dom”:“ 16.2.0”,“ react-big-calendar”:“ ^ 0.20.1”,“ moment”:“ ^ 2.22.2”,
有人对这些问题有解决方案吗?
我知道这是一个问题,但是它涉及的是不需要本地化程序的较旧版本。
import * as React from 'react';
import BigCalendar from 'react-big-calendar';
import * as moment from 'moment';
class CalendarContainer extends React.Component {
constructor(props: any) {
super(props);
}
render() {
const localizer = BigCalendar.momentLocalizer(moment);
return (
<>
<BigCalendar localizer={localizer} events={events} />
</>
);
}
}
export default CalendarContainer;
答案 0 :(得分:0)
您可能想尝试将本地化器从渲染中拉出。
import * as React from 'react';
import BigCalendar from 'react-big-calendar';
import * as moment from 'moment';
const localizer = BigCalendar.momentLocalizer(moment);
class CalendarContainer extends React.Component {
constructor(props: any) {
super(props);
}
render() {
return (
<>
<BigCalendar localizer={localizer} events={events} />
</>
);
}
}
export default CalendarContainer;
答案 1 :(得分:0)
您可以尝试以下代码...
BigCalendar.setLocalizer(BigCalendar.momentLocalizer(moment));
答案 2 :(得分:0)
我遇到了同样的问题:
import moment from 'moment';
import { Calendar, momentLocalizer } from 'react-big-calendar';
import 'react-big-calendar/lib/css/react-big-calendar.css';
const localizer = momentLocalizer(moment);
class CalendarContainer extends React.Component {
constructor(props: any) {
super(props);
}
render() {
return (
<>
<Calendar localizer={localizer} events={events} />
</>
);
}
}
export default CalendarContainer;