0

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

1 Answer 1

2

overdueCalculation method should be declared as static method. eg

export default class overdueChecker {
     static overdueCalculation = (bookingEnd) => {
        // method body
     }
}
Sign up to request clarification or add additional context in comments.

2 Comments

same issue. checkingStatus__.a.overdueCalculation is not a function is the error i am getting
woops made an error with import. this actually worked

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.