Reputation: 159
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;
};
}
Upvotes: 1
Views: 1405
Reputation: 801
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)
});
Upvotes: 2