Is there any other way to show the month,year except dropdown in react-datepicker?

Gorakh Nath picture Gorakh Nath · Sep 5, 2017 · Viewed 11.2k times · Source

I am using react-datepicker but for some reason, we don't want to show the month and year in the dropdown.

<DatePicker
    selected={this.state.startDate}
    onChange={this.handleChange}
    peekNextMonth
    showMonthDropdown
    showYearDropdown
    dropdownMode="select"
/>

Is there any other way to show the month and year?

Answer

MDK picture MDK · Apr 29, 2020

To show only Month and Year Dropdown, try this.

<DatePicker
  dateFormat="MMMM yyyy"
  showMonthYearPicker
  selected={this.state.startDate}
  onChange={this.handleChange}
/>

ref: link