Ad

Why Is Moment Undefined In My Fullcalendar-scheduler Implementation In React?

- 1 answer

There are no issues when I only implement fullcalendar, but I get a moment error when I try to implement fullcalendar-scheduler.

Here is my code:

var $ = require('jquery');
require('moment');
require('fullcalendar');
require('fullcalendar-scheduler');

And my react class:

var Calendar = React.createClass({

    componentDidMount: function () {

        var resources = this.props.venues;

        $('#calendar').fullCalendar({
            defaultView: 'agendaWeek',
            events: [

            ],
            resources: resources
        });
    },

    render: function () {
        return (
            <div id='calendar'></div>
        );
    }
});

Simply commenting out the require('fullcalendar-scheduler') line allows my code to run, and the calendar pops up. But including it gives me this error:

Uncaught ReferenceError: moment is not defined

I saw in this thread that I should include moment before fullcalendar, which I am doing.

Any thoughts?

Ad

Answer

ReactJS does not support global variables, which is what this calendar seems to need. You may use Flux or Redux, which has the ability to add these things.

The other option is to import the moment.js into the head of the document, which will attach a global variable.

Ad
source: stackoverflow.com
Ad