React-calendar: Set calendar view

Created on 21 May 2020  路  3Comments  路  Source: wojtekmaj/react-calendar

Hello

Many thanks for creating this wonderful tool.

I have implemented a date range selector with two drop down calendars, the first to select the start date and the second to select the end date. My problem is that both calendars open on the month of the start date. Is it possible to set the second calendar to open on the month of end date?

Thanks again!

question

All 3 comments

@guydewinton Hi! Yes this package is a wonderful tool indeed!

Can you show us some code?
Do you have two react-calendars instantiated in a component? In that case you could simply set two different activeStartDates

It's a little hard without the code sample, but there are several possible implementations you could have done:

  • Passing first value to the both calendars - in this case all you need is simply fix it to pass the second one to it :)
  • Passing [startValue, endValue] to both calendars - in this case you will need to add activeStartDate to the second calendar to force it to display 2nd calendar. Be careful though, this causes Calendar's activeStartDate to be completely controlled and you will need to handle onActiveStartDateChange callback as well.
  • Calculating activeStartDate once and passing it to both calendars - in this case you'd need to calculate it separately for both calendars.

Got it all working. I used the date range with activeStartDate and controlled everything. Really nice API! Thanks!

Was this page helpful?
0 / 5 - 0 ratings

Related issues

dumkanki picture dumkanki  路  4Comments

Hubro picture Hubro  路  3Comments

wojtekmaj picture wojtekmaj  路  5Comments

tranvula picture tranvula  路  4Comments

mikeyharris89 picture mikeyharris89  路  4Comments