From 6581360fece1aaf7b7044354e28fbf9e24d309ef Mon Sep 17 00:00:00 2001 From: HaixingOoO <974758671@qq.com> Date: Thu, 26 Dec 2024 22:07:20 +0800 Subject: [PATCH] feat(form): optimize setField same not rerender --- src/form/FormItem.tsx | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/form/FormItem.tsx b/src/form/FormItem.tsx index 262c7f9969..affa3da3b0 100644 --- a/src/form/FormItem.tsx +++ b/src/form/FormItem.tsx @@ -9,6 +9,7 @@ import { CloseCircleFilledIcon as TdCloseCircleFilledIcon, ErrorCircleFilledIcon as TdErrorCircleFilledIcon, } from 'tdesign-icons-react'; +import isEqual from 'lodash/isEqual'; import { calcFieldValue } from './utils'; import useConfig from '../hooks/useConfig'; import useGlobalIcon from '../hooks/useGlobalIcon'; @@ -165,7 +166,9 @@ const FormItem = forwardRef((originalProps, ref isUpdatedRef.current = true; shouldValidate.current = validate; valueRef.current = newVal; - setFormValue(newVal); + if (!isEqual(formValue, newVal)) { + setFormValue(newVal); + } }; // 初始化 rules,最终以 formItem 上优先级最高