2
import Calendar from 'react-big-calendar'
Calendar.setLocalizer(Calendar.momentLocalizer(moment))

With plugins version:

"moment": "^2.24.0"
"react-big-calendar": "^0.23.0"

After updating react big calendar package i'm getting this error. I have installed the package multiple times after update .

But getting this error "Uncaught TypeError: Cannot read property 'setLocalizer' of undefined ".

I have already read answers related to "Cannot read property 'momentLocalizer' of undefined " , but its not working for me. please help.

Thanks in advance

Ryan Nghiem
  • 2,417
  • 2
  • 18
  • 28
Sreerag
  • 73
  • 1
  • 7

2 Answers2

2

This would work:

import { Calendar, momentLocalizer } from 'react-big-calendar'
import moment from 'moment'

const localizer = momentLocalizer(moment)

const MyCalendar = props => (
  <div>
    <Calendar
      localizer={localizer}
      events={myEventsList}
      startAccessor="start"
      endAccessor="end"
      style={{ height: 500 }}
    />
  </div>
)
Jawad ul hassan
  • 565
  • 1
  • 4
  • 19
1

You need to do the following:

import { Calendar, momentLocalizer } from 'react-big-calendar';
import moment from 'moment';

const localizer = momentLocalizer(moment);

In your JSX:

  <div style={{ height: '500pt'}}>
              <Calendar
                 ....
                defaultDate={moment().toDate()}
                localizer={localizer}
              />
            </div>

I hope it helps!

Sunny Parekh
  • 945
  • 7
  • 17