React-native-calendars: state update is preventing the CalendarList rendering

Created on 4 Nov 2019  路  4Comments  路  Source: wix/react-native-calendars

Description

When month is changed, onVisibleMonthsChangeis triggered where I am doing the data fetching. Since Data fetching is an asynchronous operation i tried to render a spinner with state update. This is where problem starts. This state update is preventing the CalendarList rendering, Instead rendering only Month and Year.

Expected Behavior

Calendar should render as shown below
jan

Observed Behavior

But it's rendering like this,
Screenshot_1572861381

Environment

[email protected]
[email protected]

It's happening in both emulator and device.

Please have a look at my code,

 <CalendarList
    ref={ref => this.calendarRef = ref}
    horizontal={true}
    pagingEnabled={true}
    hideArrows={false}
    onPressArrowLeft={() => this.onArrowPress('left')}
    onPressArrowRight={() => this.onArrowPress('right')}
    onVisibleMonthsChange={months => this.onSwipeMonths(months)}
/>

onSwipeMonths(months) {
            this.setState({loaderflag: true})  // this line causes the above mentioned issue
    let { month, dateString } = months[0];
    if (months.length == 1 && this.state.calendarDate.getMonth() != (month - 1)) {
        let selectedMonth = new Date(dateString);
        this.getCalendarData(selectedMonth);
    }   
}
Question stale

Most helpful comment

I'm experiencing the very same issue. Whenever I use this.setState() on onVisibleMonthsChange, it fails to render months more than 1 apart from the initial one.

Actually, solution from https://github.com/wix/react-native-calendars/issues/884 helped with this one. I can see that it has already been commited to the master branch but it doesn't seem to be included in any release yet.

Can somebody maybe clarify, if there are plans to make a new release soon by any chance?

All 4 comments

I'm experiencing the very same issue. Whenever I use this.setState() on onVisibleMonthsChange, it fails to render months more than 1 apart from the initial one.

Actually, solution from https://github.com/wix/react-native-calendars/issues/884 helped with this one. I can see that it has already been commited to the master branch but it doesn't seem to be included in any release yet.

Can somebody maybe clarify, if there are plans to make a new release soon by any chance?

@Xiltyn Glad to know that there is a solution for this issue. BTW, the link you mentioned above pointing to the same issue. Did you meant to refer any other link?

@Yandamuri This is the link for the issue with the solution: https://github.com/wix/react-native-calendars/issues/884

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

sommeshEwall picture sommeshEwall  路  3Comments

ercpereda picture ercpereda  路  4Comments

srichallamalla935 picture srichallamalla935  路  4Comments

matieux picture matieux  路  4Comments

nickitatkach picture nickitatkach  路  4Comments