React-dates: initialVisibleMonth as previous month and this month

Created on 8 Mar 2017  路  2Comments  路  Source: airbnb/react-dates

I'm trying to use the DateRangePicker for a dashboard where you select only past dates. Now I've found the way to reverse the outside range via #209 but I also want the initialVisibleMonth to start with the previous month + this month.

How do I use initialVisibleMonth to do so?

Most helpful comment

Hi @cheeminjun! You would do the following:

initialVisibleMonth={() => moment().subtract(1, 'month')}

You might also want to cache moment() in your constructor or somewhere similar so as to avoid creating a new moment object on every render.

All 2 comments

Hi @cheeminjun! You would do the following:

initialVisibleMonth={() => moment().subtract(1, 'month')}

You might also want to cache moment() in your constructor or somewhere similar so as to avoid creating a new moment object on every render.

Cheers!

Was this page helpful?
0 / 5 - 0 ratings