【问题标题】:React js react-big-calendar momentLocalizer of undefinedReact js react-big-calendar momentLocalizer of undefined
【发布时间】:2019-09-13 23:35:33
【问题描述】:

我尝试在此处和 github 上搜索有关该项目的信息,但找不到使其工作的解决方案。

目前它给了我以下错误:

Cannot read property 'momentLocalizer' of undefined

代码行错误:

const localizer = BigCalendar.momentLocalizer(moment);

示例:Link

代码:

import React, { Component } from "react";
import { render } from "react-dom";
import events from "./events";
import BigCalendar from "react-big-calendar";
import moment from "moment";
import "react-big-calendar/lib/css/react-big-calendar.css";

moment.locale("en");
const localizer = BigCalendar.momentLocalizer(moment);
const allViews = Object.keys(BigCalendar.Views).map(k => BigCalendar.Views[k]);

class App extends Component {
  state = {
    view: "day",
    date: new Date(2015, 3, 12),
    width: 500
  };

  render() {
    console.log(
      moment()
        .subtract(1, "months")
        .endOf("month")
        .format("YYYY-MM-DD")
    );
    return (
      <div style={{ height: 700 }}>
        <BigCalendar
          localizer={localizer}
          onRangeChange={e => {
            console.log(e);
          }}
          events={[]}
          startAccessor="start"
          endAccessor="end"
        />
      </div>
    );
  }
}

render(<App />, document.getElementById("root"));

【问题讨论】:

    标签: javascript reactjs momentjs react-big-calendar


    【解决方案1】:

    您正在使用命名导入。你能把你的导入修改成这个吗?

    import { momentLocalizer } from "react-big-calendar";
    // Rest of your code
    const localizer = momentLocalizer(moment);
    // Rest of your code
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-03-26
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多