Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Performance : limit rerender of calendar #2430

Open
matthieuMay opened this issue Mar 13, 2024 · 0 comments
Open

Performance : limit rerender of calendar #2430

matthieuMay opened this issue Mar 13, 2024 · 0 comments

Comments

@matthieuMay
Copy link

matthieuMay commented Mar 13, 2024

Description

On first render Calendar components render twice. This is due to a re-parse of current month made in a useEffect

Expected Behavior

Only one render when data do not change

Fix

The re-render can be fixed by applying this patch-package:

diff --git a/node_modules/react-native-calendars/src/calendar/index.js b/node_modules/react-native-calendars/src/calendar/index.js
index 6f46e8a..45f0104 100644
--- a/node_modules/react-native-calendars/src/calendar/index.js
+++ b/node_modules/react-native-calendars/src/calendar/index.js
@@ -28,7 +28,10 @@ const Calendar = (props) => {
     const weekNumberMarking = useRef({ disabled: true, disableTouchEvent: true });
     useEffect(() => {
         if (initialDate) {
-            setCurrentMonth(parseDate(initialDate));
+            const parsed = parseDate(initialDate);
+            if (currentMonth.getTime() !== parsed.getTime()) {
+                setCurrentMonth(parseDate(initialDate));
+            }
         }
     }, [initialDate]);
     useDidUpdate(() => {
@matthieuMay matthieuMay changed the title Performance : limit rerenders Performance : limit rerender of calendar Mar 13, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant