Reputation: 1566
Having a slight issue with returning a value.
So I currently have a react project, and have a component which is as follows:
<List>
{bookings.map((booking) =>
<ListItem
onChange={onChange}
id={booking.bookingId}
overdue = {CheckingStatus.overdueCalculation(booking.bookingEnd)}
initial={booking.customer.initial.substring(0,1)+booking.customer.lastName.substring(0,1)}
name={booking.customer.initial +'. '+ booking.customer.lastName}
reference={'REF: '+booking.bookingReference}
setStyle={selected!=null && selected.id===booking.bookingId ? true : false}
/>
)}
</List>
However it keeps failing at overdue = {CheckingStatus.overdueCalculation(booking.bookingEnd)}
The CheckingStatus.js is as follows:
import moment from 'moment'
export default class overdueChecker {
static overdueCalculation = (bookingEnd) => {
//set 1 to grace period of next day 1am
var d1 = new Date()
d1.setDate(d1.getDate() + 1);
d1.setHours(1)
d1.setMinutes(0)
d1.setSeconds(0)
var d2 = new Date(bookingEnd)
//determine if overdue
if(d1.getTime()>d2.getTime()){
this.setState({warning : true})
} else {
this.setState({warning : false})
}
//calculate days overdue
var d1m = moment(d1)
var d2m = moment(d2)
var diff = d1m.diff(d2m,'days')
return diff
}
}
Any ideas
Upvotes: 0
Views: 91
Reputation: 509
overdueCalculation method should be declared as static method. eg
export default class overdueChecker {
static overdueCalculation = (bookingEnd) => {
// method body
}
}
Upvotes: 2