StephenChou1017 / react-big-scheduler

A scheduler and resource planning component built for React and made for modern browsers (IE10+)
https://stephenchou1017.github.io/scheduler/#/
MIT License
754 stars 414 forks source link

TypeError: Cannot read property '_setDocumentWidth' of undefined #148

Closed phoon0901 closed 5 years ago

phoon0901 commented 5 years ago

I tried to follow your demo . However, I received an error TypeError: Cannot read property '_setDocumentWidth' of undefined at index.js in line 173. schedulerData._setDocumentWidth(document.documentElement.clientWidth);

Anyone know how to solve this?

vladdedita commented 5 years ago

Did you manage to solve this? I'm running into the same problem.

dandanknight commented 4 years ago

I think this will be due to the scheduleData object not been created in time before the component renders

dgo2dance commented 4 years ago

Anyone know how to solve this?

SirPhemmiey commented 4 years ago

Guys, any luck with this please? @duanshuyong0 @dandanknight @phoon0901

despatates commented 4 years ago

I encountered this issue, this was because schedulerData was not correctly initialized in my class.

class MyPlanning extends React.Component {
  schedulerData = undefined;

  componentDidMount() {
    this.schedulerData = new SchedulerData(/* ... */);
    // [ ... ]
  }

  render() {
    return (
      <Scheduler
        schedulerData={this.schedulerData} // <- this.schedulerData is undefined.
        prevClick={this.prevClick}
        nextClick={this.nextClick}
        onSelectDate={this.onSelectDate}
        onViewChange={this.onViewChange}
        eventItemClick={this.eventClicked}
      />
    );
  }
}

this.schedulerData is undefined at first render because componentDidMount() is called after first render() call. So check schedulerData before using it.

render() {
  return this.schedulerData ? <Scheduler schedulerData={this.schedulerData} { ... } /> : null;
}

Hope this helps.