0

在我的项目中,我试图初始化 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;
4

3 回答 3

2

我有同样的问题:

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;
于 2019-08-29T10:39:41.640 回答
1

您可能想尝试将定位器从渲染中拉出。

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;
于 2018-10-30T20:50:40.297 回答
0

你可以试试下面的代码...

BigCalendar.setLocalizer(BigCalendar.momentLocalizer(moment));
于 2019-08-29T09:30:04.593 回答