diff --git a/components/lib/calendar/Calendar.js b/components/lib/calendar/Calendar.js index 612ec640a1..234c33f278 100644 --- a/components/lib/calendar/Calendar.js +++ b/components/lib/calendar/Calendar.js @@ -47,6 +47,7 @@ export const Calendar = React.memo( const ignoreMaskChange = React.useRef(false); const previousButton = React.useRef(false); const nextButton = React.useRef(false); + const onChangeRef = React.useRef(null); const [currentView, setCurrentView] = React.useState('date'); const [currentMonth, setCurrentMonth] = React.useState(null); @@ -1424,7 +1425,7 @@ export const Calendar = React.memo( viewStateChanged.current = true; - props.onChange({ + onChangeRef.current({ originalEvent: event, value: newValue, stopPropagation: () => { @@ -2517,6 +2518,11 @@ export const Calendar = React.memo( } }); + React.useEffect(() => { + // see https://github.com/primefaces/primereact/issues/4030 + onChangeRef.current = props.onChange; + }, [props.onChange]); + React.useEffect(() => { let unbindMaskEvents = null;