Selecting a date on a different month than the default causes calendar to redraw default month
See original GitHub issueI have the following simple set up:
<Calendar
onDayPress={day => onChangeDate(day)}
monthFormat={'MMMM yyyy'}
/>
When the calendar renders I click the forward month arrow, then select a date. In my onChangeDate
function I store that date in state. Doing that causes the calendar to re-render and it resets to the original default month. If I use markedDates
and set the selected date as selected
I can see it selected, when I scroll back to the correct month, but this is pretty useless for me since the calendar resets back to the default month as soon as I select any date outside that default month.
Issue Analytics
- State:
- Created 6 years ago
- Reactions:1
- Comments:12 (3 by maintainers)
Top Results From Across the Web
Solved: How to set current date as default date in date pi...
Another alternative, which is probably preferred, is to "Reset" the date picker control - which causes its selected date to go back to...
Read more >Solved: Current month default selection in Slicers, so tha...
'Current Month' can always be your default value with others available to select. This means that when you subscribe it will happily roll...
Read more >Editing dates and date ranges - Zendesk help
Selecting Last Week within the time filter should default to Monday - Sunday but as you can see the dates shown reflect Sunday...
Read more >Date Properties for a Data Source - Tableau Help
Default calendar - Specifies which calendar system to use: Standard Gregorian or ... the workbook locale rather than the data source's Week start...
Read more >Default Current Month Slicer in Power BI - YouTube
Link to download the Calendar file ⏬There's no built-in way to default the slicer selection to the current month. But 2 extra Power...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Hi, I have investigated this bug. It looks like the problem is that each time the FlatList is rerendered calendar component is being constructed (constructor is being called). That is the reason the calendar forgets current month. Not sure why this happens in flatlist.
However there is a workaround to solve this. You could add property
current = {(this.state.selectedDate && selectedDate.format('YYYY-MM-DD')) || new Date()}
to calendar. This would achieve the result you want. Event if calendar is constructed on each day press it would get selected day as current month and would show correct month. However you should consider that having calendar to be reinitialized on each day press could somewhat impact your app performance.it actually works with this code
{(this.state.selectedDate) || new Date()}
without the format check