diff --git a/src/AbstractQuickEdit.tsx b/src/AbstractQuickEdit.tsx index fa595e5..94a016f 100644 --- a/src/AbstractQuickEdit.tsx +++ b/src/AbstractQuickEdit.tsx @@ -78,6 +78,9 @@ const register =

any, value?: unknown }) => { const [editValue, setEditValue] = useDerivedState(value); const containerRef = useRef(null); + const editValueRef = useRef(editValue); + editValueRef.current = editValue; + const [shouldRenderEditComponent, switchShouldRenderEditComponent] = useDerivedState(editing); const {defaultEditComponentProps, disableEnterKey} = options; @@ -172,16 +175,18 @@ const register =

any, value?: unknown ); const onChangeValueByEffect = useCallback( - updator => { + (updator?: any) => { + // ensure the value is new value + const editValue = editValueRef.current; if (typeof updator === 'function') { handleOnChangeWhenValueChanged(updator(editValue)); } else { - handleOnChangeWhenValueChanged(updator); + handleOnChangeWhenValueChanged(editValue); } switchEditStatus(false); }, - [editValue, handleOnChangeWhenValueChanged, switchEditStatus] + [handleOnChangeWhenValueChanged, switchEditStatus] ); const contextValue = useMemo( @@ -193,7 +198,7 @@ const register =

any, value?: unknown setTimeout( () => { if (shouldRenderEditComponent) { - onChangeValueByEffect(editValue); + onChangeValueByEffect(); } }, 0 @@ -225,7 +230,7 @@ const register =

any, value?: unknown {...defaultEditComponentProps} disabled={disabled} onChange={handleChange} - value={editValue} + value={value} /> ) : ( displayComponent