question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Cannot read property '0' of undefined

See original GitHub issue

Do you want to request a feature or report a bug?

Bug

What’s the current behavior?

https://stackoverflow.com/questions/50210199/react-big-calendar-cannot-read-property-0-of-undefined

While implementing the basic project, the back and next buttons do not work. I get the following error:

Month.js:217 Uncaught TypeError: Cannot read property ‘0’ of undefined at MonthView.renderHeaders (Month.js:217) at MonthView.render (Month.js:209) at finishClassComponent (react-dom.development.js:8389) at updateClassComponent (react-dom.development.js:8357) at beginWork (react-dom.development.js:8982) at performUnitOfWork (react-dom.development.js:11814) at workLoop (react-dom.development.js:11843) at HTMLUnknownElement.callCallback (react-dom.development.js:100) at Object.invokeGuardedCallbackDev (react-dom.development.js:138) at invokeGuardedCallback (react-dom.development.js:187)

Upon closer inspection it fails here:

MonthView.prototype.renderHeaders = function renderHeaders(row, format, culture) {
    //failes here.
    var first = row[0];
    var last = row[row.length - 1];
    var HeaderComponent = this.props.components.header || _Header2.default;

    return _dates2.default.range(first, last, 'day').map(function (day, idx) {
      return _react2.default.createElement(
        'div',
        { key: 'header_' + idx, className: 'rbc-header' },
        _react2.default.createElement(HeaderComponent, {
          date: day,
          label: _localizer2.default.format(day, format, culture),
          localizer: _localizer2.default,
          format: format,
          culture: culture
        })
      );
    });
  };

After playing around with the project, it would appear the current date is not correctly set. Once I click on the button “today” it works as intended.

My code:

import React, {Component} from 'react';
import BigCalendar from 'react-big-calendar';
import moment from 'moment';

// Setup the localizer by providing the moment (or globalize) Object
// to the correct localizer.
BigCalendar.setLocalizer(BigCalendar.momentLocalizer(moment))

export default class CalendarComponent extends Component {

    constructor(props){
        super(props);



        this.state = {
            events: []
        }

    }

    render(){
        return (
            <div style={{flex: 1}}>
                <BigCalendar
                    events={this.state.events}
                    startAccessor='startDate'
                    endAccessor='endDate'
                />
            </div>
        );
    }
}

What’s the expected behavior?

Expected to have working back and next buttons to change dates.

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:5

github_iconTop GitHub Comments

8reactions
rottenoatscommented, May 7, 2018

@SLYtiger16 I tried with defaultDate prop and it worked. Thanks.

<div style={{flex: 1}}>
                <BigCalendar
                    events={this.state.events}
                    startAccessor='startDate'
                    endAccessor='endDate'
                    defaultDate={moment().toDate()}
                />
</div>

Though I don’t believe it should be specified (?), and it needs to be mentioned somewhere in the documentation other than the example source in the docs.

0reactions
FranciscoGilenocommented, May 13, 2018

+1

Read more comments on GitHub >

github_iconTop Results From Across the Web

TypeError: Cannot read Property '0' of Undefined in JS
The "Cannot read property '0' of undefined" error occurs when trying to access the 0th index in a variable that stores an undefined...
Read more >
How To Fix Cannot read Property '0' of Undefined in JS
The Solution · Ensure you are using the correct variable · Perform a simple check on your variable before using it to make...
Read more >
How to Prevent the Error: Cannot Read Property '0' of Undefined
If a property of an object is an array, it's possible to accidentally misspell the key or try to access the array through...
Read more >
Javascript Uncaught TypeError: Cannot read property '0' of ...
You are passing the first item of words , instead of the array. Instead, pass the array to the function: hasLetter("a",words);.
Read more >
npm error cannot read property 0 of undefined
npm error cannot read property 0 of undefined · delete node_modules folder · delete package-lock.json · do “npm install” to recreate your node_modules...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found