React-calendar: How to use formatMonthYear or formatShortWeekday these functions?

Created on 13 Dec 2019  路  2Comments  路  Source: wojtekmaj/react-calendar

I tried a lot about how to use formatMonthYear, formatShortWeekday? But couldn't write code properly. I need to use the single letter week names. Please need help

        formatShortWeekday = () => {
          value => ['S', 'M', 'T', 'W', 'T', 'F', 'S'][value.getDay()]
        }


         render() {
          return (
            <CalendarInput
              value='' // Need to implement
              returnValue="range"
              calendarType="US"
              className={classes.calendar}
              onChange={() => {
                // Need to implement
              }}
              formatShortWeekday={this.formatShortWeekday}
            />
          );
         }

Getting errors, I believe there is some syntax mistake.
I followed this issue https://github.com/wojtekmaj/react-calendar/issues/34 but not cleared how to use any of these formatDate functions.
Please help.

question

Most helpful comment

As documentation states, formatShortWeekday gets two arguments: locale, date. You need to .getDay() on date that is given as an argument, and it should work just fine.

  formatShortWeekday = (locale, date) => ['S', 'M', 'T', 'W', 'T', 'F', 'S'][date.getDay()]

All 2 comments

As documentation states, formatShortWeekday gets two arguments: locale, date. You need to .getDay() on date that is given as an argument, and it should work just fine.

  formatShortWeekday = (locale, date) => ['S', 'M', 'T', 'W', 'T', 'F', 'S'][date.getDay()]

And how do you do it locale-dependent? I'm trying to use the exact example from the documentation
(locale, date) => formatDate(date, 'dd')

but I keep getting the following error:
Calendar.js:94 Uncaught TypeError: Object(...) is not a function

Was this page helpful?
0 / 5 - 0 ratings

Related issues

spoldman picture spoldman  路  4Comments

fasmart4 picture fasmart4  路  6Comments

tranvula picture tranvula  路  4Comments

Muttakee31 picture Muttakee31  路  4Comments

amansur picture amansur  路  6Comments