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.

Changing state on onMonthChange doesn't move to the next/prev month

See original GitHub issue

I’m trying to show the busy days in the calendar using the markedDates property. For the month I’m currently showing I build the markedDays hashtable dynamically from a SQLite database. When I click the next arrow in the calendar I use onMonthChange to call the method that updates the markedDates list. The list is updated correctly, however the month doesn’t move to the next.
I believe I was able to isolate the issue using the code provided in the example. Here’s an excerpt of ./example/src/screens/calendar.js with my changes:

`export default class CalendarsScreen extends Component { constructor(props) { super(props); this.state = { markedDates :{ ‘2017-07-24’: {selected: true, marked: true}, ‘2017-07-25’: {marked: true}, ‘2017-07-30’: {marked: true}, } }; this.onDayPress = this.onDayPress.bind(this); }

monthChange(month) { console.log(‘month changed2’,month); this.setState({ markedDates :{ ‘2017-07-01’: {selected: true, marked: true}, ‘2017-07-02’: {marked: true}, } });

} render() { return ( <ScrollView style={styles.container}> <Text style={styles.text}>Calendar with selectable date and arrows</Text> <Calendar onDayPress={this.onDayPress} onMonthChange={(month) => {this.monthChange.bind(this)(month)}} style={styles.calendar} current={‘2017-07-17’} hideExtraDays markedDates={ this.state.markedDates} `

If I comment out the “setState” call on the monthChange method, the next/prev arrows work correctly. However if I uncomment the setState, the month doesn’t change when the arrows are clicked.

Great work btw!

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:8 (4 by maintainers)

github_iconTop GitHub Comments

5reactions
tautvilascommented, Aug 3, 2017

set state causes rerender of calendar, since you current does not match the date in calendar it is being reset to current. If you want to start from older month you can set current as older month but as month changes also update current value:

monthChange(month) {
 this.setState({currentdate: month})
}
0reactions
tautvilascommented, Aug 3, 2017

thanks!

Read more comments on GitHub >

github_iconTop Results From Across the Web

Listener for "date change" in FullCalendar? - Stack Overflow
I want this functionality to be able to sync the currently viewed month in FullCalendar with a ExtJS datepicker component, so if the...
Read more >
Calendar doesn't change to next or previous month -
I am looking at the calendar now and it's pointing to December. No November is listed. When I click to List View, November...
Read more >
View Raw - UNPKG
*Only use when the readable text does not change between states.* */ isSelected?: boolean; /** * Extends the button to 100% width */...
Read more >
Navigating Months - React DayPicker
Navigating Months. Change the default month​. DayPicker displays the month of the current day. To change the default month, set the defaultMonth prop....
Read more >
Falcon Sandbox v8.30 © Hybrid Analysis
... month view is re-rendered. We * only register the event handlers once per page load so that the in place * DOM...
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