diff --git a/src/useForm.ts b/src/useForm.ts index a0aa8eef..895da920 100644 --- a/src/useForm.ts +++ b/src/useForm.ts @@ -566,7 +566,7 @@ export class FormStore { if (onValuesChange) { const changedValues = cloneByNamePathList(this.store, [namePath]); - onValuesChange(changedValues, this.store); + onValuesChange(changedValues, this.getFieldsValue()); } this.triggerOnFieldsChange([namePath, ...childrenFields]); @@ -780,7 +780,7 @@ export class FormStore { function useForm(form?: FormInstance): [FormInstance] { const formRef = React.useRef(); - const [, forceUpdate] = React.useState(); + const [, forceUpdate] = React.useState({}); if (!formRef.current) { if (form) { diff --git a/tests/index.test.js b/tests/index.test.js index 1b90d83b..58e0d1d3 100644 --- a/tests/index.test.js +++ b/tests/index.test.js @@ -212,6 +212,35 @@ describe('Form.Basic', () => { expect(onChange).toHaveBeenCalledWith(expect.objectContaining({ target: { value: 'Bamboo' } })); }); + it('onValuesChange should not return fully value', async () => { + const onValuesChange = jest.fn(); + + const Demo = ({ showField = true }) => ( +
+ {showField && ( + + + + )} + + + +
+ ); + + const wrapper = mount(); + await changeValue(getField(wrapper, 'bamboo'), 'cute'); + expect(onValuesChange).toHaveBeenCalledWith(expect.anything(), { + light: 'little', + bamboo: 'cute', + }); + + onValuesChange.mockReset(); + wrapper.setProps({ showField: false }); + await changeValue(getField(wrapper, 'bamboo'), 'beauty'); + expect(onValuesChange).toHaveBeenCalledWith(expect.anything(), { bamboo: 'beauty' }); + }); + it('submit', async () => { const onFinish = jest.fn(); const onFinishFailed = jest.fn();