I'm using react-big-calendar And need help to implement localization which is required The example from git
import BigCalendar from 'react-big-calendar';
import moment from 'moment';
BigCalendar.setLocalizer(
BigCalendar.momentLocalizer(moment)
);
My code
var moment = require('moment');
var momentLocalizer = require('react-widgets/lib/localizers/moment');
import BigCalendar from 'react-big-calendar';
BigCalendar.setLocalizer(
BigCalendar.momentLocalizer(moment.locale('en'))
);
let MyCalendar = props => (
<div>
<BigCalendar
/>
</div>
);
Whatever I tried it doesn't work
Uncaught TypeError: moment is not a function
I'm using react-big-calendar And need help to implement localization which is required The example from git
import BigCalendar from 'react-big-calendar';
import moment from 'moment';
BigCalendar.setLocalizer(
BigCalendar.momentLocalizer(moment)
);
My code
var moment = require('moment');
var momentLocalizer = require('react-widgets/lib/localizers/moment');
import BigCalendar from 'react-big-calendar';
BigCalendar.setLocalizer(
BigCalendar.momentLocalizer(moment.locale('en'))
);
let MyCalendar = props => (
<div>
<BigCalendar
/>
</div>
);
Whatever I tried it doesn't work
Share Improve this question asked Apr 9, 2016 at 8:24 victor zadorozhnyyvictor zadorozhnyy 9691 gold badge13 silver badges27 bronze badgesUncaught TypeError: moment is not a function
2 Answers
Reset to default 11I had to import the locale I wanted to get the calendar in the correct locale.
Notice the import 'moment/locale/nb';
.
import React, { Component } from 'react';
import BigCalendar from 'react-big-calendar';
import moment from 'moment';
import 'moment/locale/nb';
import 'react-big-calendar/lib/css/react-big-calendar.css';
BigCalendar.setLocalizer(BigCalendar.momentLocalizer(moment));
class Calendar extends Component {
constructor() {
super();
this.state = {
events: [],
};
}
render() {
return (
<div className="Calendar">
<BigCalendar
events={this.state.events}
/>
</div>
);
}
}
This is for version 0.17.0 of react-big-calendar.
My code below, it works for me. I simply set the culture
prop on my BigCalendar if I want to change localization.
import React, { Component } from 'react';
import 'react-big-calendar/lib/css/react-big-calendar.css'
import BigCalendar from 'react-big-calendar';
import moment from 'moment';
BigCalendar.momentLocalizer(moment);
class Calendar extends Component {
constructor(props, context) {
super(props, context);
}
render() {
return (
<div>
<BigCalendar
culture='en-GB'
events={this.props.tasks}
views={['month', 'week']}/>
</div>
);
}
}