From a3d4e5d9c671106b9ae6202b6e4dc7092e16f72a Mon Sep 17 00:00:00 2001 From: Sara Date: Thu, 5 Dec 2024 09:38:38 +0000 Subject: [PATCH] [WOM-5333] Wrap BpkCalendar format date methods with memoize (#3689) * Wrap BpkCalendar format date methods with memoize * Improvements * Improvement * Add memoize for formatMonth only to avoid double calls * Add TS doc * Add licence header to test file --- .../src/BpkCalendarGrid.tsx | 3 +- .../src/composeCalendar.tsx | 5 +- .../bpk-component-calendar/src/utils-test.ts | 70 +++++++++++++++++++ packages/bpk-component-calendar/src/utils.ts | 50 +++++++++++++ 4 files changed, 125 insertions(+), 3 deletions(-) create mode 100644 packages/bpk-component-calendar/src/utils-test.ts diff --git a/packages/bpk-component-calendar/src/BpkCalendarGrid.tsx b/packages/bpk-component-calendar/src/BpkCalendarGrid.tsx index 60808f2982..77085f5319 100644 --- a/packages/bpk-component-calendar/src/BpkCalendarGrid.tsx +++ b/packages/bpk-component-calendar/src/BpkCalendarGrid.tsx @@ -30,6 +30,7 @@ import { getCalendarMonthWeeks, isSameMonth, } from './date-utils'; +import { memoize } from './utils'; import type { DateModifiers, SelectionConfiguration } from './custom-proptypes'; @@ -170,7 +171,7 @@ class BpkCalendarGrid extends Component { dates={dates} onDateClick={onDateClick} onDateKeyDown={onDateKeyDown} - formatDateFull={formatDateFull} + formatDateFull={memoize(formatDateFull)} DateComponent={DateComponent} dateModifiers={dateModifiers!} preventKeyboardFocus={preventKeyboardFocus} diff --git a/packages/bpk-component-calendar/src/composeCalendar.tsx b/packages/bpk-component-calendar/src/composeCalendar.tsx index ec2bfc10c7..178f3e618b 100644 --- a/packages/bpk-component-calendar/src/composeCalendar.tsx +++ b/packages/bpk-component-calendar/src/composeCalendar.tsx @@ -21,6 +21,7 @@ import type { ComponentType } from 'react'; import { cssModules } from '../../bpk-react-utils'; import { CALENDAR_SELECTION_TYPE } from './custom-proptypes'; +import { memoize } from './utils'; import type { DaysOfWeek, @@ -184,7 +185,7 @@ const composeCalendar = ( {Nav && (