diff --git a/components/form/FormItem.tsx b/components/form/FormItem.tsx index 196ae76ec3..54b9e2b71a 100644 --- a/components/form/FormItem.tsx +++ b/components/form/FormItem.tsx @@ -122,12 +122,15 @@ function FormItem(props: FormItemProps): React.ReactElement { const updateChildItemErrors = noStyle ? updateItemErrors : (subName: string, subErrors: string[]) => { - if (!isEqual(inlineErrors[subName], subErrors)) { - setInlineErrors(prevInlineErrors => ({ - ...prevInlineErrors, - [subName]: subErrors, - })); - } + setInlineErrors((prevInlineErrors = {}) => { + if (!isEqual(prevInlineErrors[subName], subErrors)) { + return { + ...prevInlineErrors, + [subName]: subErrors, + }; + } + return prevInlineErrors; + }); }; // ===================== Children Ref ===================== diff --git a/components/form/__tests__/index.test.js b/components/form/__tests__/index.test.js index 65e5fe1c71..ba15bbe44c 100644 --- a/components/form/__tests__/index.test.js +++ b/components/form/__tests__/index.test.js @@ -40,24 +40,78 @@ describe('Form', () => { scrollIntoView.mockRestore(); }); - it('noStyle Form.Item', async () => { - const onChange = jest.fn(); + describe('noStyle Form.Item', () => { + it('work', async () => { + const onChange = jest.fn(); - const wrapper = mount( -