adjustDayPickerHeight not calculating predictably when setting numberOfMonths prop dynamically
See original GitHub issueOn our project, we’re using a grid system that optionally passes us a screenClass prop to tell us what breakpoint we’re currently in. We’re using that breakpoint to pass a numberOfMonths prop to the DayPickerRangeController to render either two months for desktop or one month for mobile.
When we’re doing this, our function initializes as sm, which initially passes numberOfMonths={1}. It’s changed to numberOfMonths={2} shortly after once window.innerWidth is captured and the method is run.
Setting it to 1 on initial load breaks adjustDayPickerHeight for a month either 2 or 3 greater than the current one. As it’s calculated based off of calendarMonthWeeks, which is only set on componentDidMount right now, that value becomes stale until it’s triggered again.

Possible Fix
Adding a check to componentDidUpdate for a variation in numberOfMonths and then triggering setCalendarMonthWeeks again fixes the issue.
Issue Analytics
- State:
- Created 5 years ago
- Reactions:3
- Comments:6 (5 by maintainers)

Top Related StackOverflow Question
Sounds like this was a misunderstanding on my part and for that, I apologize. Thanks for stepping in and clearing it up. Looks like #2095 was created by someone following this thread and has been rebased!
All I wanted to ensure is that your new test passes, even if the other tests next to it don’t. You implied that you’d be able to get them all passing, so I asked if you’d mind doing that in a separate PR, but #1415 deletes existing tests and it wasn’t clear to me that it was the proper approach. After that it seems like neither of us revisited #1395. If you’re willing to rebase it, I can get it landed.