react-native-calendars: Agenda crashes with RN 0.78
After switching to RN 0.78, the Agenda component crashes with the infamous
Warning: Error: Maximum update depth exceeded. This can happen when a component repeatedly calls setState inside componentWillUpdate or componentDidUpdate. React limits the number of nested updates to prevent infinite loops. This error is located at: at ReservationList (http://10.0.2.2:8081/index.bundle//&platform=android&dev=true&lazy=true&minify=false&app=com.calendartest&modulesOnly=false&runModule=true&excludeSource=true&sourcePaths=url-server:103469:36) at RCTView (<anonymous>) at View (http://10.0.2.2:8081/index.bundle//&platform=android&dev=true&lazy=true&minify=false&app=com.calendartest&modulesOnly=false&runModule=true&excludeSource=true&sourcePaths=url-server:47523:43) at RCTView (<anonymous>) at View (http://10.0.2.2:8081/index.bundle//&platform=android&dev=true&lazy=true&minify=false&app=com.calendartest&modulesOnly=false&runModule=true&excludeSource=true&sourcePaths=url-server:47523:43) at Agenda (http://10.0.2.2:8081/index.bundle//&platform=android&dev=true&lazy=true&minify=false&app=com.calendartest&modulesOnly=false&runModule=true&excludeSource=true&sourcePaths=url-server:97582:36)
About this issue
- Original URL
- State: open
- Created 2 years ago
- Reactions: 7
- Comments: 32 (9 by maintainers)
I was messing around a little bit, and the issue seems to be coming from here in the
ReservationListcomponent class.I think the problem is with the prevProps !== this.props check. I modified it slightly to test it out:
This initially fixes it when you are looking at the current week at the top, but when you switch to the full month selection that no longer works. So there is more that needs done or updated, or maybe i missed the true issue completely.
I created a PR, with slightly updated coding. It looks the the other error I encountered is only on Android devices, and is there even in the current version on older version or RN as well.
Here is a link to the PR
There are at least 2 PR’s with fixes. Let’s see what WIX team will do about it.
Code example:
Open your project directory.
Navigate to: node_modules/react-native-calendars/src/agenda/reservation-list/index.js Open the File for Editing
Open index.js.
Find the componentDidUpdate Method
Search for componentDidUpdate in the file.
Replace the Method with the Updated One
Replace the existing componentDidUpdate with the following code:
componentDidUpdate(prevProps) { if ( this.props.topDay && prevProps.topDay && ( !sameDate(prevProps.topDay, this.props.topDay) || prevProps.items !== this.props.items || prevProps.selectedDay !== this.props.selectedDay ) ) { if (!sameDate(prevProps.topDay, this.props.topDay)) { this.setState({ reservations: [] }, () => this.updateReservations(this.props)); } else { this.updateReservations(this.props); } } }
#2624 is a possible fix. Let’s see what the team chooses to implement.
I got the same error. The issue is related with React 19 which is shipped with RN 0.78. When I downgraded to RN 0.77 with React 18.3.1, the issue is solved.
I’ve encountered various bugs with React 19 when using other packages, so it’s safer to stick with the previous version for now.
@shareef-dweikat - It’s mentioned above
@Lewitje , @gkasireddy202 It looks like this has a different cause. Maybe you fill in another issue.
@bmatasar and @neeleshyadav253 - Thanks