diff --git a/src/Field.tsx b/src/Field.tsx index 69e680ce..0f20fcd1 100644 --- a/src/Field.tsx +++ b/src/Field.tsx @@ -606,6 +606,7 @@ class Field extends React.Component implements F this.dirty = true; this.triggerMetaEvent(); + const curValue = this.getValue(); let newValue: StoreValue; if (getValueFromEvent) { @@ -615,9 +616,9 @@ class Field extends React.Component implements F } if (normalize) { - newValue = normalize(newValue, value, getFieldsValue(true)); + newValue = normalize(newValue, curValue, getFieldsValue(true)); } - if (newValue !== value) { + if (newValue !== curValue) { dispatch({ type: 'updateValue', namePath, diff --git a/tests/field.test.tsx b/tests/field.test.tsx index ad053d93..8f2ff01c 100644 --- a/tests/field.test.tsx +++ b/tests/field.test.tsx @@ -3,7 +3,6 @@ import Form, { Field } from '../src'; import type { FormInstance } from '../src'; import { act, fireEvent, render } from '@testing-library/react'; import { Input } from './common/InfoField'; -import { getInput } from './common'; import timeout from './common/timeout'; describe('Form.Field', () => { @@ -73,4 +72,38 @@ describe('Form.Field', () => { onValuesChange.mockReset(); } }); + + // https://github.com/react-component/field-form/issues/753 + it('value change multiple times', async () => { + const form = React.createRef(); + const MockBtnInput = props => ( + <> + + + + ); + const { container } = render( +
+ + + +
, + ); + + // Trigger + for (let i = 0; i < 3; i += 1) { + fireEvent.click(container.querySelector('button')); + await act(async () => { + await timeout(); + }); + expect(form.current?.getFieldValue('input')).toBe('A'); + } + }); });