Stefan B
Stefan B

Reputation: 229

React-dates initialMonth based on available dates

I have date-picker component (DayPickerSingleDateController). There is "

isoutsiderange

property (available only +4 (from to day) days. )

But because of this an error occurs. Event if current month don't have available dates it still shows current month onClick.

Now i trying to add initialMonth property in which I would like to check if there are not dates available in this month, then () => moment().add(1, 'month').

initialVisibleMonth={.... () => moment().add(1, 'month')}
isOutsideRange={(day) => isInclusivelyBeforeDay(day, moment().add(4, 'days'))}

How can i do that?

Upvotes: 0

Views: 1227

Answers (1)

Stefan B
Stefan B

Reputation: 229

I got the following solution for my problem.

I declared the isAvailableDaysInCurrentMonth variable like this.

const firstAvailableDay = moment().add(3, 'days') // in my situation, i need "not earlier then 3 days"
const isCurrentMonthExcludeAvailableDate = (moment().month() !== firstAvailableDay.month());

Now i can set initial month in singleDatePicker. So if there are not available dates in current month, then set next month for show.

<DayPickerSingleDateController
 ...
 initialVisibleMonth={isCurrentMonthExcludeAvailableDate ? () => moment().add(1, 'month') : null}
>

I found this answer myself, maybe there is a more elegant solution, but still it may be useful for someone.

Upvotes: 3

Related Questions