@@ -41,6 +41,8 @@ export type RangeProps = BaseProps & {
4141
4242export type CalendarProps = SingleProps | MultipleProps | RangeProps ;
4343
44+ const SelectionTypeContext = React . createContext < SelectionType > ( 'single' ) ;
45+
4446export function Calendar ( props : SingleProps ) : JSX . Element ;
4547export function Calendar ( props : MultipleProps ) : JSX . Element ;
4648export function Calendar ( props : RangeProps ) : JSX . Element ;
@@ -61,11 +63,13 @@ export function Calendar(props: CalendarProps): JSX.Element {
6163 const selectionType = props . selectionType ?? 'single' ;
6264 const defaults = getDefaultClassNames ( ) ;
6365
64- const DayBtn = useMemo (
65- ( ) => ( p : React . ComponentProps < typeof RdpDayButton > ) =>
66- < CalendarDayButton selectionType = { selectionType } { ...p } /> ,
67- [ selectionType ]
68- ) ;
66+ const MemoCalendarDayButton = React . memo ( CalendarDayButton ) ;
67+ MemoCalendarDayButton . displayName = 'MemoCalendarDayButton' ;
68+
69+ const DayButtonComp = ( p : React . ComponentProps < typeof RdpDayButton > ) => {
70+ const ctxSelectionType = React . useContext ( SelectionTypeContext ) ;
71+ return < MemoCalendarDayButton selectionType = { ctxSelectionType } { ...p } /> ;
72+ } ;
6973
7074 const common = {
7175 showOutsideDays : false ,
@@ -82,7 +86,7 @@ export function Calendar(props: CalendarProps): JSX.Element {
8286 if ( orientation === 'right' ) return < ChevronRightIcon size = { 24 } { ...p } /> ;
8387 return null as unknown as React . ReactElement ;
8488 } ,
85- DayButton : DayBtn ,
89+ DayButton : DayButtonComp ,
8690 ...( components ?? { } )
8791 } ,
8892 ...rest
0 commit comments