Skip to content

Commit

Permalink
fix(react): fix useField/useVirtualField props assign (#858)
Browse files Browse the repository at this point in the history
  • Loading branch information
janryWang authored May 18, 2020
1 parent aa80fcf commit e71e527
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 4 deletions.
7 changes: 5 additions & 2 deletions packages/react/src/hooks/useField.ts
Original file line number Diff line number Diff line change
@@ -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,
Expand Down Expand Up @@ -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)
Expand Down
7 changes: 5 additions & 2 deletions packages/react/src/hooks/useVirtualField.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down Expand Up @@ -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)
}
Expand Down

0 comments on commit e71e527

Please sign in to comment.