@@ -7,7 +7,6 @@ import React, {
77 FC ,
88 useRef ,
99 useState ,
10- useEffect ,
1110 useContext ,
1211} from 'react' ;
1312import classnames from 'classnames' ;
@@ -184,6 +183,13 @@ export const DateInput = createFC<DateInputProps, { isFormElement: boolean }>(
184183
185184 const { getActiveElement } = useContext ( ComponentSettingsContext ) ;
186185
186+ const onChangeValue = useEventCallback ( ( newValue : string | null ) => {
187+ if ( newValue !== value ) {
188+ onValueChange ?.( newValue , value ) ;
189+ setValue ( newValue ) ;
190+ }
191+ } ) ;
192+
187193 const setValueFromInput = useEventCallback ( ( inputValue : string ) => {
188194 let newValue = value ;
189195 if ( ! inputValue ) {
@@ -196,7 +202,7 @@ export const DateInput = createFC<DateInputProps, { isFormElement: boolean }>(
196202 newValue = '' ;
197203 }
198204 }
199- setValue ( newValue ) ;
205+ onChangeValue ( newValue ) ;
200206 setInputValue ( null ) ;
201207 } ) ;
202208
@@ -217,15 +223,9 @@ export const DateInput = createFC<DateInputProps, { isFormElement: boolean }>(
217223 }
218224 }
219225 setOpened ( true ) ;
220- setValue ( newValue ) ;
226+ onChangeValue ( newValue ) ;
221227 } ) ;
222228
223- const prevValueRef = useRef < typeof value > ( value ) ;
224- useEffect ( ( ) => {
225- onValueChange ?.( value , prevValueRef . current ) ;
226- prevValueRef . current = value ;
227- } , [ value , onValueChange ] ) ;
228-
229229 const onDateIconClick = useEventCallback ( ( ) => {
230230 inputElRef . current ?. focus ( ) ;
231231 setTimeout ( ( ) => {
@@ -281,7 +281,7 @@ export const DateInput = createFC<DateInputProps, { isFormElement: boolean }>(
281281
282282 const onDatepickerSelect = useEventCallback ( ( dvalue : string ) => {
283283 const value = moment ( dvalue ) . format ( valueFormat ) ;
284- setValue ( value ) ;
284+ onChangeValue ( value ) ;
285285 setInputValue ( null ) ;
286286 setTimeout ( ( ) => {
287287 setOpened ( false ) ;
0 commit comments