Skip to content

Commit 9cb1685

Browse files
committed
fix: preserve sibling values for nested list changes
1 parent 9718bdc commit 9cb1685

1 file changed

Lines changed: 1 addition & 7 deletions

File tree

src/hooks/useForm.ts

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import { merge } from '@rc-component/util/lib/utils/set';
2-
import { mergeWith } from '@rc-component/util';
32
import warning from '@rc-component/util/lib/warning';
43
import * as React from 'react';
54
import { HOOK_MARK } from '../FieldContext';
@@ -779,14 +778,9 @@ export class FormStore {
779778
const { onValuesChange } = this.callbacks;
780779

781780
if (onValuesChange) {
782-
const fieldEntity = this.getFieldsMap(true).get(namePath);
783781
const changedValues = cloneByNamePathList(this.store, [namePath]);
784782
const allValues = this.getFieldsValue();
785-
// Merge changedValues into allValues to ensure allValues contains the latest changes
786-
const mergedAllValues = mergeWith([allValues, changedValues], {
787-
// When value is array, it means trigger by Form.List which should replace directly
788-
prepareArray: current => (fieldEntity?.isList() ? [] : [...(current || [])]),
789-
});
783+
const mergedAllValues = setValue(allValues, namePath, getValue(changedValues, namePath));
790784
onValuesChange(changedValues, mergedAllValues);
791785
}
792786

0 commit comments

Comments
 (0)