1

I'm new to Node/Webpack/React. When I switch between month/week/day view, the app often crashes and I get this error in the console: index.js?07ad:209 Uncaught TypeError: date[("get" + method)] is not a function.

please help me thanks

Code

          <MyCalendar
                popup
                selectable
                localizer={localizer}
                defaultView={[MyCalendar.Views.WEEK ]}
                components={{toolbar: CustomToolbar}}
                views={['week']}
                style={{height: 600}}
                events={this.props.events}
                eventPropGetter={(this.eventStyleGetter)}
                onSelectEvent={(slotInfo) => this.onSelectEventHandler(slotInfo)}
                onSelectSlot={(slotInfo) => this.onSelectEventSlotHandler(slotInfo)}
            />

Function

function createAccessor(method) {
  return function (date, val) {
    if (val === undefined) return date['get' + method]();
    date = new Date(date);
    date['set' + method](val);
    return date;
  };
}
Jonas
  • 149
  • 3
  • 10
  • 2
    You have to post the function that crash – Andrea - codemillers.com Aug 06 '19 at 09:24
  • @Andrea-codemillers.com please check question , I just updated my question and added function – Jonas Aug 06 '19 at 09:27
  • 1
    the combination of `'get' + method` is not returning a valid Function from `date`, that's what causes the error. – Sultan H. Aug 06 '19 at 09:33
  • You can debug via `console.log` for both `date` and `method` which will give you an insight of which of these is giving the wrong value. – Sultan H. Aug 06 '19 at 09:34
  • @SultanH. could you please help me how to solve this problem – Jonas Aug 06 '19 at 09:34
  • https://stackoverflow.com/questions/988363/how-can-i-debug-my-javascript-code – Ricola Aug 06 '19 at 09:38
  • to additing these startAccessor='startDate' endAccessor='endDate' . Error gone but events are not showing in calendar – Jonas Aug 06 '19 at 09:49
  • I would love to do so, I was wondering where is `createAccessor` invoked from? can you `console.log` the `method` and `date` at the beginning of the function that is returned from `createAccessor` and show the result? – Sultan H. Aug 06 '19 at 09:54
  • This question is a duplicate of https://stackoverflow.com/questions/57287782/typeerror-dateget-method-is-not-a-function-in-react-big-calendar. See my answer in that question. – Steve -Cutter- Blades Feb 16 '20 at 16:03

1 Answers1

2

this happens when the date you are trying to display is "String" when actually "date" is an "Object" type, then you could do something like this:

var DATEString = "2020-08-31T05:00:00.000Z"
var dateLike = new Date(DATEString)

example my code:

ReqCitas.data.forEach(cita => {
      Object.assign(cita,{ "uuid": uuidv4()})
      cita.start =  new Date(cita.start)
      cita.end =  new Date(cita.end)
});
AN German
  • 725
  • 10
  • 10