question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Selecting a date on a different month than the default causes calendar to redraw default month

See original GitHub issue

I 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:closed
  • Created 6 years ago
  • Reactions:1
  • Comments:12 (3 by maintainers)

github_iconTop GitHub Comments

3reactions
tautvilascommented, Aug 17, 2017

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.

2reactions
giacomokcommented, Sep 27, 2017

it actually works with this code {(this.state.selectedDate) || new Date()} without the format check

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found