diff --git a/packages/react/src/hooks/useField.ts b/packages/react/src/hooks/useField.ts index 42e6ae37ac5..3faed6eb033 100644 --- a/packages/react/src/hooks/useField.ts +++ b/packages/react/src/hooks/useField.ts @@ -1,5 +1,5 @@ import { useMemo, useEffect, useRef, useContext } from 'react' -import { isFn, uid } from '@formily/shared' +import { isFn, uid, merge } from '@formily/shared' import { IFieldState, IForm, @@ -93,7 +93,10 @@ export const useField = (options: IFieldStateUIProps): IFieldHook => { const props = inspectChanged(cacheProps, options, INSPECT_PROPS_KEYS) if (props) { ref.current.field.setState((state: IFieldState) => { - Object.assign(state, props) + merge(state, props, { + assign: true, + arrayMerge: (target, source) => source + }) }) } ref.current.field.setCache(ref.current.uid, options) diff --git a/packages/react/src/hooks/useVirtualField.ts b/packages/react/src/hooks/useVirtualField.ts index ec7a08152d6..3a10494e216 100644 --- a/packages/react/src/hooks/useVirtualField.ts +++ b/packages/react/src/hooks/useVirtualField.ts @@ -6,7 +6,7 @@ import { IVirtualField, LifeCycleTypes } from '@formily/core' -import { uid } from '@formily/shared' +import { uid, merge } from '@formily/shared' import { useForceUpdate } from './useForceUpdate' import { IVirtualFieldHook } from '../types' import { inspectChanged } from '../shared' @@ -57,7 +57,10 @@ export const useVirtualField = ( const props = inspectChanged(cacheProps, options, INSPECT_PROPS_KEYS) if (props) { ref.current.field.setState((state: IVirtualFieldState) => { - Object.assign(state, props) + merge(state, props, { + assign: true, + arrayMerge: (target, source) => source + }) }) ref.current.field.setCache(ref.current.uid, options) }